VB.NET - Selected Index Changed Event - Asked By thushara nireesh on 15-Sep-10 02:30 AM

In  the form load event
 cmbSystem.SelectedItem = DataGridView1.Rows(rowID).Cells(2).Value
when i run the project and comes to cmbSystem..SelectedItem = DataGridView1.Rows(rowID).Cells(2).Value
it is going to cmbSystem selected index changed event .How can i avoid this. I dont want to go to Selected Index Changed Event
Reena Jain replied to thushara nireesh on 15-Sep-10 02:52 AM
hi,

If you have taken any selected indexchange even you can't stop it to fire. alternate you can put a condition in selectedIndex change event, that don't execute the code you have written in event for a specific operation.

hope this will give you a proper hint

Rolf Jaeger replied to thushara nireesh on 15-Sep-10 02:55 AM
Hi Thushara:

my way of routinely dealing with a situation like this is to introduce a public boolean variable, e.g. 'Dim b_ByPassOn as Boolean' and then insert the following statement at the beginning of the SelectedIndexChanged event:

If b_ByPassOn Then Exit Sub

and then set the variable to True before you change the SelectedItem property and back to False after you changed the SelectedItem property:

b_ByPassOn = True
cmbSystem.SelectedItem = DataGridView1.Rows(rowID).Cells(2).Value
b_ByPassOn = False

This may not be the most elegant solution, but it does the trick.

Hope this helped,
Rolf
Anurag replied to thushara nireesh on 15-Sep-10 02:58 AM
cmbSystem.SelectedItem.Text = DataGridView1.Rows(rowID).Cells(2).Text;
Try this and please update.
Super Man replied to thushara nireesh on 15-Sep-10 11:26 AM
take one public bool variable and set it to False


whenever page_loads set it to true


and on selected index change event 

check vaiable is T/F. if it is false , then an only execute, otherwise  do nothing.
Goniey N (Mr. G) replied to thushara nireesh on 15-Sep-10 11:23 PM
-- Try This :

-- Here It Will Check That If Flag=0 If Yes Then Execute It & Make It As "1" & Then It Will Not Execute Again & Agian...
1.Dim Flag As Integer = 0
2.If Flag = 0 Then
3.  cmbSystem.SelectedItem = DataGridView1.Rows(rowID).Cells(2).Value
4.  Flag = 1
5.End If


-- Hope This Will Help You...
Jon replied to thushara nireesh on 10-Apr-11 11:00 PM

Most of the time I dont want the index changed handler to fire when I am populating the thing, dropdowns, list boxes etc. So I just look to see if the control sending the event has focus. If I really need to make sure the event does not fire I will make sure the particular control does not have focus.


Private Sub ToolStripComboBox6_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ToolStripComboBox6.SelectedIndexChanged

'history navigation

Dim s As ToolStripComboBox = sender

If Not s.Focused Then

Exit Sub

End If

MsgBox("it hit")

End Sub