VB.NET - Selected index changed event-urgent

Asked By thushara on 25-May-11 02:53 AM

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick

 If Not cmbProductDesc.Text = "Installation & Testing Charges" Then
            If Not IsDBNull(DataGridView1.Rows(rowID).Cells(3).Value) Then
              cmbSubSystem.Text = Trim(DataGridView1.Rows(rowID).Cells(3).Value)

            Else
              cmbSubSystem.Text = ""

            End If
          End If

end sub

When it comes to this line of line(    cmbSubSystem.Text = Trim(DataGridView1.Rows(rowID).Cells(3).Value)) ,obviously it will call selected index changed event. Is there any way to restrict this,

dipa ahuja replied to thushara on 25-May-11 03:42 AM
you have written the code to change the combo 's selected value.. then how can you restrict it.. because that code definately change the value and when value will change selectedIndex will be changed/
Reena Jain replied to thushara on 25-May-11 08:20 AM
hi,

you can set the flag on page load and then can check the flag value to not run the code under selected indexchange event like on page load set it 0 and set it one where you are assigning the value to combobox and check on selected index change event like this

if(flag=0)then
{
//code to run
}

hope this will solve your problem
Reena Jain replied to thushara on 25-May-11 08:20 AM
hi,

same thing is discussed here also

http://www.eggheadcafe.com/community/aspnet/14/10200969/selected-index-changed-event.aspx

Hope this will help you