Solved

Fire one event when a BindingSource's Current object's property changes.

Posted on 2009-07-14
2
3,765 Views
Last Modified: 2013-12-17
I have a BindingSource (employeeBindingSource) who's DataSource is an object array (Employee[]).

It is bound to a BindingNavigator, a ToolStripComboBox, and several Common Windows Form Controls.

GOAL: Fire only one event when the user changes a bound value. Such as text in a TextBox, state of a CheckBox, value of a DateTimePicker, etc.

PROBLEM: I am handling the CurrentItemChanged event but whenever the user changes a text value, this event gets fired twice on validation. According to MSDN, this is expected since it is fired once for the property change and again for the CurrentChanged.

I tried to handle the ListChanged event and checked the ListChangedType for ItemChanged. I got the same results. The event was fired twice!

QUESTION:
So, which event(s) will allow me to detect changes in a BindingSource's Current properties just once per change?
employeeBindingSource.DataSource = _hrClient.GetEmployees(null, null, true, false);

employeeBindingSource.CurrentItemChanged += employeeBindingSource_CurrentItemChanged;

employeeBindingSource.ListChanged += employeeBindingSource_ListChanged;

bindingNavigator.BindingSource = employeeBindingSource;
 

......
 

// The following methods allowed me to see the events fired multiple times
 

private void employeeBindingSource_CurrentItemChanged(object sender, EventArgs e)

{

    string text = lstPastStudiesEmp.Items.Count + " CurrentItemChanged";

    listbox1.Items.Insert(0, text);

}
 

private void employeeBindingSource_ListChanged(object sender, ListChangedEventArgs e)

{

    string text = lstPastStudiesEmp.Items.Count + " " + e.ListChangedType;

    lstPastStudiesEmp.Items.Insert(0, text);

}

Open in new window

0
Comment
Question by:RyanAndres
2 Comments
 
LVL 12

Expert Comment

by:topdog770
ID: 24864971
Have you tried just using CurrentChanged ?  It should fire anytime the data changes, but not until then.
 
 
 
0
 
LVL 8

Accepted Solution

by:
RyanAndres earned 0 total points
ID: 24865206
CurrentChanged will fire everytime the Current changes (the position) rather than its properties.

I have found a workaround, which is to use the PropertyChanged event on my DataSource's objects except this isn't built into the BindingSource itself. Before I assign my dataobjects to the datasource I attach each object's PropertyChanged event to an event handler for further processing whenever a value changes.

I will use this solution for now until I find a better one that works specifically with bindingsources.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Expando 4 33
Code works but how can I download the file? 20 45
fomat Json objects 6 15
Unable  to create new object 9 22
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now