VB.NET Detected user changes in a Bound Combobox

How do I detect user changes in a Bound Combobox without having the event fire during loading and bindingsource changes?  The problem is that I only want one a specific event to fire when a user clicks or uses the keyboard to make a change.  The problem with the SelectedIndexChanged event is that it fires all the time, including when the BindingSource1 data is loaded/changed, and when the Bindinsource2.position changes.  Any relatively easily solution without a complicated set of flags, etc?

For a combobox named [b]cboStuff[/b]:
cboStuff.Datasource = BindingSource1
DisplayMember = WidgetDescription
ValueMember = WidgetID

[b]SelectedValue = BindingSource2 - WidgetID[/b]

Open in new window

eeyoAsked:
Who is Participating?
 
Ryan ChongCommented:
try make a public variable like a Boolean and place it into the SelectedIndexChanged event to verify if it's in Binding stage, if yes, then doing the escape else continue to run your codes.

like:

Public isBinding As Boolean = Flase

Open in new window


then:
...
isBinding = True
cboStuff.Datasource = BindingSource1
DisplayMember = WidgetDescription
ValueMember = WidgetID
isBinding = False

Open in new window


in SelectedIndexChanged , just check:

If isBinding Then Exit Sub
'your other codes here

Open in new window

0
 
Éric MoreauSenior .Net ConsultantCommented:
instead of using the designer to bind your control to the code (by adding the handles clause to the method), you could use the AddHandler call to manually subscribe to the events you want after you have set the DataSource
0
 
eeyoAuthor Commented:
These both work when the form is loading, but what about when there is a position change for BindingSource2?  I am not sure which events to use to turn on/off the flag to prevent the SelectedIndexChanged from firing.
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Éric MoreauSenior .Net ConsultantCommented:
You can also call RemoveHandler on the same events before changing the datasource
0
 
eeyoAuthor Commented:
If the bindingsource.position changes when a user clicks on a different row in the bound datagridview, which Datagridview or Bindingsource event can I use before any of the bound combobox events fire?  Both the combobox and datagridview are bound to the same bindingsource.
0
 
eeyoAuthor Commented:
No perfect resolution.  Perhaps having a bound combobox that is used to make selections on another bound datarow is too complicated.  It's easier to just use a pop-up form to work on a single bound datarow at a time.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.