PC Review


Reply
Thread Tools Rate Thread

BindingSource and CurrentChanged event

 
 
dvestal@gmail.com
Guest
Posts: n/a
 
      13th Sep 2011
The included program produces this output to the debug stream:

Changed!
Changed!
Changed!

Why does the event fire three times? Can I configure it such that it
only fires when the Current item is actually different?

My source program follows:

using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowsApplication3
{
static class Program
{
[STAThread]
static void Main()
{
BindingSource src = new BindingSource();
BindingList<string> list = new BindingList<string>(
new string[]
{
"Odd"
}
);

src.CurrentChanged += new EventHandler(src_CurrentChanged);
src.DataSource = list;
}

static void src_CurrentChanged(object sender, EventArgs e)
{
Debug.WriteLine("Changed!");
}
}
}
 
Reply With Quote
 
 
 
 
dvestal@gmail.com
Guest
Posts: n/a
 
      14th Sep 2011
On Sep 13, 7:12*pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.com> wrote:
> On 9/13/11 1:22 PM, dves...@gmail.com wrote:
>


> Fortunately, it should not be difficult to treat consecutive invocations
> of the event handler when the Current property has not really changed,
> simply by keeping track of what the property was the last time the event
> was raised and comparing it to the current Current value.
>
> In any case, I do recommend submitting a bug on the Connect web site, to
> at least see what Microsoft says about it. *Maybe they'd even offer a
> better work-around than I have.
>
> In the meantime, you can console yourself with the fact that this guy is
> seeing the event being raised not three times, but FOUR:http://social.msdn.microsoft.com/for...atacontrols/th...
>
> And no one ever replied to his question at all. *
>
> Pete


Thanks, Peter. When the property changes, I do some expensive
processing that's not _quite_ expensive enough to stick in a non-GUI
thread...unless it happens 3 times.

I worked around it by setting the datasource first, then subscribing
to the event. In the event handler and immediately after subscribing
to the event, I call a function that does the work, so I avoid the
initial glut of events.
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wpf datagrid ctp cell selection changed causes sometimes no CurrentChanged event Winfried Wille Microsoft C# .NET 0 20th Oct 2008 08:18 AM
Need for BindingSource.Removing event jehugaleahsa@gmail.com Microsoft C# .NET 2 11th Dec 2007 07:33 PM
BindingNavigator event when BindingSource changes Rick Microsoft VB .NET 0 24th Jun 2007 02:44 PM
BindingSource.CurrentItemChanged event Ceefour Microsoft ADO .NET 0 20th Sep 2006 12:42 PM
CurrentChanged event DOESNT get fired with Framework v1.1 Newsgroups MICROSOFT Microsoft VB .NET 2 15th Dec 2004 12:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:57 AM.