, , , , . , . IndexChanging - ComboBox, .
@AftabAhmedKalhoro @jeffamaphone, Tag.
ComboBox - , . Tag, , ( VB6).
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("Item1")
ComboBox1.Items.Add("Item2")
ComboBox1.Items.Add("Item3")
ComboBox1.Items.Add("Item4")
' Load Value from database or whatever and set the value or index.
ComboBox1.SelectedIndex = 0
ComboBox1.Tag = ComboBox1.SelectedIndex
' I add the handler at the end because I don't want it to fire during loading the form.
AddHandler ComboBox1.SelectedIndexChanged, New EventHandler(AddressOf ComboBox1_SelectedIndexChanged)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If (ComboBox1.Tag <> ComboBox1.SelectedIndex) Then
If MessageBox.Show("Warning! You are changing the index." & vbCrLf & _
"Do you wish to continue?", _
"Changing Index", _
MessageBoxButtons.YesNo, _
MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes Then
ComboBox1.Tag = ComboBox1.SelectedIndex
' Do Something.
Else
ComboBox1.SelectedIndex = ComboBox1.Tag
End If
End If
End Sub
, SelectedIndex , :
ComboBox1.SelectedIndex = ComboBox1.Tag