Results 1 to 13 of 13

Thread: ListView (clearning variables)

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    41

    ListView (clearning variables)

    OK professionals out there, here's a hard one for you. I have made a program. When I exit the catalog part of it and back to the main menu system I have, then go back to the catalog part and look at the listview, all the items I picked are still there. Isn't there away upon exiting to remove those items? Please help me in this matter.

  2. #2
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335
    Sure there is. Just put "Clearlistview" in the part of code you use to exit the catolog.

    Code:
    Public Sub ClearListView()
    
    On Error GoTo errdone
    
    Dim Di As Integer
    For Di = 1 To ListView1.ListItems.Count
    
    ListView1.ListItems.Remove (1)
    Next Di
    
    Exit Sub
    errdone: MsgBox Error
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  3. #3
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Originally posted by JasonLpz
    Sure there is. Just put "Clearlistview" in the part of code you use to exit the catolog.

    Code:
    Public Sub ClearListView()
    
    On Error GoTo errdone
    
    Dim Di As Integer
    For Di = 1 To ListView1.ListItems.Count
    
    ListView1.ListItems.Remove (1)
    Next Di
    
    Exit Sub
    errdone: MsgBox Error
    isnt here a Di ?

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    List1.ListItems.Clear. This is the code you need.
    Last edited by amitabh; Sep 28th, 2002 at 10:54 AM.

  5. #5
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    lv.listitems.clear

    Put this in your form_unload or query_unload events...

  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by amitabh
    List1.ListItems.Clear. This is the code you need.
    ListView not listbox
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  7. #7
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Yes, I misread it first, then corrected it. Forgot to correct List1 to Listview1

  8. #8
    Frenzied Member JasonLpz's Avatar
    Join Date
    Mar 2001
    Location
    Brooklyn, NY
    Posts
    1,335

    Here,

    OK I got it here for you. I made a entire example (simple example). The ZIP includes the compiled EXE and the VB6 Source
    Attached Files Attached Files
    - JayWare
    Live to love. Not to Hate

    Im to busy to have a site. But I got one and still working on it.

    http://dre3k.net/

  9. #9
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    It's the weekend, and I am on vbForums Actually only logged on to get a copy of my badger

    The code to clear a listview is:
    VB Code:
    1. ListView1.ListItems.Clear
    Oh, and in the above example where someone has used a loop to remove each listitem individually, you have to step backwards, that code won't work. You need:
    VB Code:
    1. For Di = ListView1.ListItems.Count To 1 Step -1
    The other thing is that in the Form_UnLoad there is no need to clear the listitems as the Terminate event of the ListView control is fired and that will automatically toast the listitems.
    Just make sure that you unload your form, and not just hide it...

    Woka

  10. #10
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Here,

    Originally posted by JasonLpz
    OK I got it here for you. I made a entire example (simple example). The ZIP includes the compiled EXE and the VB6 Source
    Hmmm...very strange way to do it...you used:
    VB Code:
    1. For x = 1 To ListView1.ListItems.Count
    2.    ListView1.ListItems.Remove (1)
    3. Next x
    Strange way to do it, the correct way would be:
    VB Code:
    1. For lngIndex = ListView1.ListItems.Count to 1 Step -1
    2.     ListView1.ListItems.Remove lngIndex
    3. Next lngIndex
    Also, I re-named x to lngIndex, this just makes it easier to debug as I know that lngIndex is the INDEX of the ListItem, and it's varible type is LONG.
    However, both ways do exactally the same thing at the end of the day, so your code is not wrong...Although you can achieve the same result in just one line of code:
    VB Code:
    1. ListView1.ListItems.Clear


    Woka

  11. #11
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Originally posted by VictorB212
    lv.listitems.clear

    Put this in your form_unload or query_unload events...
    No need. When the form unloads the listviews Terminate event is fired, and in there it will destroy all the ListItems automatically for you
    If you could see the code it would look something like:
    VB Code:
    1. Private Sub UserControl_Terminate()
    2.    Set mobjListItems = nothing
    3. End Sub
    Woka

  12. #12
    Fanatic Member
    Join Date
    Jun 2001
    Posts
    521
    Err, my mistake, the control is not necessarily unloaded; that's why the listview needs to be cleared. So put it wherever it should go...

  13. #13
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Why is the control not unloaded?
    If the form is unloaded then the control will be destroyed.
    However, objects may not be destroyed, as you may have another reference to them elsewhere in your app.

    Woka

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width