Listview Bug, Surely?

T

Toff McGowen

Hi

I have a form with a listview on it. When an item is selected it causes
other controls on the form to be filled with data related to that item. If
the data is dirty then i want to check that with the user using a
cancel/yes/no message box before filling the detail control with the data of
the newly selected item.

If the user <cancels> then i want to reset the listview to item associated
with the data displayed in the other controls. The following code is used:

Private Sub OnSelectedTerritoryChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs)

If Me.Initializing OrElse Me.Binding OrElse _isTerritoryReset Then Exit
Sub

' Prevent event capture occuring twice for single territory change
If Me.lvSalesTerritories.SelectedItems.Count <> 1 Then Exit Sub

RemoveHandler lvSalesTerritories.SelectedIndexChanged, AddressOf
Me.OnSelectedTerritoryChanged
If VerifyChanges() Then
ShowTerritory()
Else
' Roll back to previous/current territory
ResetTerritoryListSelectedItem()
End If
AddHandler lvSalesTerritories.SelectedIndexChanged, AddressOf
Me.OnSelectedTerritoryChanged
End Sub

Private Sub ResetTerritoryListSelectedItem()

Dim i As Integer
Dim focusedTerritory As dsSalesTerritory.SalesTerritoryRow

With Me.lvSalesTerritories
_isTerritoryReset = True

For i = 0 To .Items.Count - 1
focusedTerritory = CType(.Items(i).Tag,
dsSalesTerritory.SalesTerritoryRow)
If focusedTerritory.SalesTerritoryId =
_currentTerritory.SalesTerritoryId Then
.Items(i).Selected = True
Exit For
End If
Next i

_isTerritoryReset = False
End With
End Sub

The problem is the yes/no/cancel messagebox is shown twice despite what ive
done to handle the slectedindexchnagd event as it fires twice (selct on :
select off). The reason i think its a bug is that if i just set a break
point on AddHandler lvSalesTerritories.SelectedIndexChanged, AddressOf
Me.OnSelectedTerritoryChanged
in the selcted index changed handler, so that the app break into debug mode,
and then press F5, the second messagebox is not shown.

Its as if there is a bug timing issue with the framework.

Any ideas?

Thanks

TM
 
M

Michael Jackson

Seems like I read that the SelectedIndexChanged event fires twice, once when
leaving the current item and again when getting the newly selected item.

Michael
 
T

Toff McGowen

Hi Michael,

Yes thanks i know about that as per my initial post. I have both flagged and
dynamically added and removed handlers to account for this. My problem is
that setting a simple breakpoint and then hitting F5 solves the issue...
which in turn suggests the problem is within the framework/win32 api.

TM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top