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.
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/
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
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:
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:
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...
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:
For x = 1 To ListView1.ListItems.Count
ListView1.ListItems.Remove (1)
Next x
Strange way to do it, the correct way would be:
VB Code:
For lngIndex = ListView1.ListItems.Count to 1 Step -1
ListView1.ListItems.Remove lngIndex
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:
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:
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.