Solved

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

Posted on 2009-07-14
2
3,876 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

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