Have problem that have troubled me for sometime now.
What i'm trying to do is to select an item in a listview when an other item is selected.
Lets say i have a list with items that have one column and that column contains A letter, the items are sorted is alphabetic order, and what i wnat to do is to select the item that contains the letter N when the user selects the item that contains the letter C.
My code looks like this:
Private Sub lvHydSerach_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvHydSerach.SelectedIndexChanged
'Do the funky shit and mark N if C is marked
If lvHydSerach.SelectedItems.Count > 0 Then
RemoveHandler lvHydSerach.SelectedIndexChanged, AddressOf Me.lvHydSerach_SelectedIndexChanged
If WasCHydrSelectedInlvHydrSearch() Then
mIsInUpdateMode = True
For Each AListItem As ListViewItem In lvHydSerach.Items
If AListItem.Text = "N" Then
lvHydSerach.Items(AListItem.Index).Selected = True
mIsInUpdateMode = False
AddHandler lvHydSerach.SelectedIndexChanged, AddressOf Me.lvHydSerach_SelectedIndexChanged
The function WasCHydrSelectedInlvHydrSearch, looks like this:
Private Function WasCHydrSelectedInlvHydrSearch() As Boolean
Static lbCWasIsSelected As Boolean
For Each AListItem As ListViewItem In lvHydSerach.SelectedItems
If AListItem.Text = "C" Then
If lbCWasIsSelected = False Then
lbCWasIsSelected = True
lbCWasIsSelected = False
What happens is this, when pressing down the mouse button on item C I can see that both C and N is selected, but when I relese the button the selection for N disapears.
If I put a breakpoint on the line which starts with RemoveHandler ....... and starts to debug it works fine, i can just press F5 and continue and both C and N is selected, but when i remove the breakpoint the problem is back.
Does anyone have a sugestion??