Ok, this one's about to walk me crazy. (I'd drive, but from where I'm
sitting, walking is probably quicker.)
I've got two forms that are open simultaneously (the first loads the
second on the first's Load event). Form 2 as a DataGridView that's
bound to a stored query (SQL Server 2005, VS2005.Net) that returns a
list of data where one of the fields is null. Form 1 has an Execut
Button that places a timestamp in that field for the top record (thus
removing it from the list).
I run the application, click the Execute Button, and nothing happens.
No surprise. I stop the application and notice the record is gone.
Again, as expected. I add a Refresh Button to Form 2 (the one with
the bound datagridview), and in the Refresh Button's OnClick event, I
fill the data table of the binding. Now when I run the application, I
click the Execute Button on Form 1, followed by the Refresh Button on
Form 2, and the DataGridView drops the top record. Life is utter
bliss.
Now, create a public delegate subroutine on Form 2 and call that
delegate at the end of the Execute Button's Click Event on Form 1.
I've tried both calling Form 2's PerformClick on the Refresh Button
and I've tried directly re-filling Form 2's datatable, but suddenly,
I've lost that lovin' feelin' and all joy is gone. In the case of the
perform click, I can set a break point inside of the event, and it's
never even being triggered. What's more, when I enter the delegate
code, Me.InvokeRequired is false. I'm not sure how or if that's
relevent, but it was certainly unexpected.
Anyone out there able to throw me a clue? I've googled and searched
the no-help-whatsoever files, but I'm not even sure what I'm supposed
to look for. I don't need help making the DataGridView refresh/
synchronize, because I'm able to do that from Form 2. I just can't do
it from Form 1. I don't believe it's a threading issue -- heck,
InvokeRequired is false. As soon as I can think of a subject to
research, I'll continue looking and post whatever solution I find, but
if anyone out there has ideas, it might save a little of the hair I
have left.
rodboggess@hotmail.com - 05 May 2008 18:28 GMT
Ok, I got this to work by creating and raising an event in Form 1 that
is captured and handled in Form 2. The event handler does nothing
other than to refill the datatable.
I still don't understand why this behaves the way it does.
Morten Wennevik [C# MVP] - 06 May 2008 06:00 GMT
Hi Rod,
Depending how you bound the DataGridView and how you update the DataSource
you may be missing a NotifyPropertyChanged or similar. This is quite common
if you use business objects as DataSource and change some property
programmatically. This can also happen if you use List<T> instead of
BindingList<T> and add or remove an item from that list. BindingList<T> will
fire a ListChanged event, but List<T> will not.

Signature
Happy Coding!
Morten Wennevik [C# MVP]
> Ok, I got this to work by creating and raising an event in Form 1 that
> is captured and handled in Form 2. The event handler does nothing
> other than to refill the datatable.
>
> I still don't understand why this behaves the way it does.