[2005] SelectedIndexChanged Problem
Hi
I have a combobox "cboPreviousPreparationEntries". Now I have a sub
Private Sub cboPreviousPreparationEntries_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPreviousPreparationEntries.SelectedIndexChanged
So this runs when the selected value of combo box is changed. Now for some reason in the code i need to put
cboPreviousPreparationEntries.SelectedIndex = 2
But at that time it calls the sub automatically as the index is changed, but I DO NOT WANT it to call that sub mentioned on top. Is that possible?
I hope i made myself clear.
Re: [2005] SelectedIndexChanged Problem
Handle the SelectionChangeCommitted event instead, which is raised only when the user makes a change through the UI.
Re: [2005] SelectedIndexChanged Problem
Quote:
What I'd do is just make a boolean (I made it public but you can send it through the function parameter list if you want):
Code:
Public ManualChange as Boolean = False
Code:
ManualChange = True
cboPreviousPreparationEntries.SelectedIndex = 2
Code:
Private Sub cboPreviousPreparationEntries_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboPreviousPreparationEntries.SelectedIndexChanged
If ManualChange = True Then
ManualChange = False
'Rest of code
End If
But I guess you could optimize it.
Wow that was easy. *slaps himself* I need to write that down.
Re: [2005] SelectedIndexChanged Problem
Quote:
Originally Posted by jmcilhinney
Handle the SelectionChangeCommitted event instead, which is raised only when the user makes a change through the UI.
Can you elaborate on this? SelectionChangeCommitted does not appear to be an event of a combo box.
Re: [2005] SelectedIndexChanged Problem
Quote:
Originally Posted by nbrege
Can you elaborate on this? SelectionChangeCommitted does not appear to be an event of a combo box.
You are kidding aren't you? Where exactly have you looked to come to that conclusion? The screen shot below shows just four ways you could have found it and they are not the only ways either.
Re: [2005] SelectedIndexChanged Problem
My mistake. I was looking at a ToolStripComboBox. I assumed it would have the same events as a standard ComboBox control.
Re: [2005] SelectedIndexChanged Problem
Quote:
Originally Posted by nbrege
My mistake. I was looking at a ToolStripComboBox. I assumed it would have the same events as a standard ComboBox control.
A ToolStripComboBox is not a ComboBox. It is a ToolStripControlHost designed to host a ComboBox. It has a ComboBox property that refers to the ComboBox it's hosting. That ComboBox has a SelectionChangedCommitted event. Alternatively you could inherit the ToolStripComboBox class and add a SelectionChangeCommitted event.