Hi folks
I have migrated from VB 6.0 to VB2002.net. I upgraded my project with the upgrade-manager. Now I find out, that the functionality of the listbox isn't the same since VB 6.0. The same code works in VB 6.0 fantastic; in VB.net not.
Here is the code:
Dim i As Integer
i = MsgBox("Really delete the marked items ", 4)
If i = 6 Then 'Yes
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then
'delete dataset in the background table .....
End If
Next i
'show new background table....
End If
(I filled the Listbox manually with List1.AddItem "item from background table".)
Anyone who can say, how to get the same functionality in vb.net , whithout having much more code Or is there anyone, who can say what's wrong with my code
(To copy the Listbox-items before and restore them at the end doesn't help, cause I delete the datasets in the background table and not in the Listbox.)
And please don' t tell me to buy the newest VB-Version: my chief won't invest nothing in that project!
Thanks for any hints
BPink

selected Items in Listbox are disseleceted by Messagebox; vb.net
Aiwa
For de-selecting all the listbox items why not simply use
Me.ListBox1.SelectedItems.Clear()No looping code required. I'm using 2005 but I'd almost certainly believe this code will work with 2002
And the latest version 2005 - you can download and use the VB Express product for free. Its full functional as it has the exact same VB Compiler as all the versions of VB. Although some advanced features of the IDE may be disabled.
Qaayam
Hi spotty
Thanks for your soon answer.
I think I have poorly explained my problem. (I'm not used to english!)
It doesn't help clearing the Listbox items. I need the selected Listbox indices to delete the underlying datasets in the background table.
My problem is, that the selected items in the listbox are not anymore selected, when the "If List1.Getselected(i) Then" is reached. That means the If-case is never reached.
Example:
before calling MsgBox (or whithout a MsgBox):
You can debug the variables List1.Selectedindex = 5 and List1.Selecteditems.count = 1;
after calling MsgBox:
List1.Selectedindex = -1 and List1.Selecteditems.count = 0
I can't understand why the selection is cleared after calling the MsgBox!
In the worst case it is a bug, which is corrected in vb2005.
Thanks for all hints
BPink
Cammyr
For i = 0 to List1.SelectedItems.Count-1
'--- Delete dataset List1.SelectedItems(i)
Next
And try finding a new chief...