VB.NET ComboBox _SelectedIndexChanged

G

Guest

Hi, I'm refreshing a panel based on a selection from a winforms combobox.
In my _SelectedIndexChanged event for the combobox, if changes to the
panel's controls are present I am checking the response from a messagebox to
proceed using MsgBoxStyle.YesNoCancel.

When clicking cancel on the messagebox, is there a way to have the combobox
rejected the changed index and revert back to the previous selection without
setting the selectedItem? Currently getting circular references when doing
that.

Code:

Private Sub cboPage_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cboPage.SelectedIndexChanged
If Not CInt(sender.SelectedItem.Value) <> _currentSetMax Then

If ItemsModified Then

Select Case MsgBox("Changes have been made, Save changes?",
MsgBoxStyle.YesNoCancel, "Items Changed")
Case MsgBoxResult.Yes
' TO DO: Save the existing controls in the panel
Case MsgBoxResult.Cancel
'TO DO: Reset the cboPage to the previous selection and return
Return
End Select

End If
' TO DO: Refresh the controls in the panel

End If

End Sub

Thanks!
 
V

vbnetdev

I would store the current setting in a variable or xml document and if the
change was rejected set the previous entry as currently selected item
(index)
 
S

Samuel Shulman

I never found a way, I believe that once this event is fired the index was
already changed

what you can do is to record to a static or class variable the index of the
selected item (After you approved the change) then if you don't like the
change you reset it to the previous recorded index
Then finally to avoid the method functionality you can Add a condition like
that

if ComboABC.SelectedIndex = iRecordedIndex then
'Ignore and exit
Else
'Perform the required functionality
......
End if


hth,
Samuel Shulman
 
G

Guest

Thanks Samuel!
I knew there had to be a workaround.
Recalling my PowerBuilder days when what I described was possible and didn't
know if it could be handled in VB.Net as I described.

--
..NET developer
VS.NET 2005 Rocks!



Samuel Shulman said:
I never found a way, I believe that once this event is fired the index was
already changed

what you can do is to record to a static or class variable the index of the
selected item (After you approved the change) then if you don't like the
change you reset it to the previous recorded index
Then finally to avoid the method functionality you can Add a condition like
that

if ComboABC.SelectedIndex = iRecordedIndex then
'Ignore and exit
Else
'Perform the required functionality
......
End if


hth,
Samuel Shulman
 

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