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
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