Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / November 2004

Tip: Looking for answers? Try searching our database.

Big Red X on DataGrid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Becker - 23 Nov 2004 03:20 GMT
I have a strange problem that happens intermittently and I cannot replicate
it on demand.  I have a datagrid that has a datasource of a datatable.

I update this datatable via threads.  I use the readerwriterlock to ensure
that multiple threads do not manipulate data in the table without having a
lock first.

The problem is that every so often, I will get an exception, probably in the
on paint method of the datagrid from what I can gather.  I'm not sure why it
happens or what causes.

Does anyone have any suggestions?

Thanks,
Ben
Ken Tucker [MVP] - 23 Nov 2004 12:37 GMT
Hi,

           It is a bug with the datagrid.  Usually it occurs when there is
an error in the paint procedure.  Make sure you have some try catch blocks
to catch the error.

Ken
------------
I have a strange problem that happens intermittently and I cannot replicate
it on demand.  I have a datagrid that has a datasource of a datatable.

I update this datatable via threads.  I use the readerwriterlock to ensure
that multiple threads do not manipulate data in the table without having a
lock first.

The problem is that every so often, I will get an exception, probably in the
on paint method of the datagrid from what I can gather.  I'm not sure why it
happens or what causes.

Does anyone have any suggestions?

Thanks,
Ben
Becker - 23 Nov 2004 12:45 GMT
I do have try catch blocks in the two main procedures that get called to do
the executing and spawning of threads, I'm just wondering where else I could
put them?  Should I somehow overload the paint method to do this?

> Hi,
>
[quoted text clipped - 22 lines]
> Thanks,
> Ben
Andrew Smith \(Infragistics\) - 27 Nov 2004 21:29 GMT
How is this a bug in the datagrid? Most likely the problem is that the fact
that Ben is updating the DataTable that the DataGrid is bound to and
therefore manipulating the DataGrid (albeit indirectly) from the background
thread since changing the DataTable will cause the grid's bindingmanager to
be raise notifications (ListChanged, etc.) to its listeners which includes
the datagrid and these notifications will occur on the background thread
since that is what he is manipulating the datatable from. I think the real
answer is to not manipulate the datatable that the datagrid is bound to from
the background thread; instead, either manipulate a copy or update a
different datatable and upon completion, marshal a call onto the ui thread
(using the datagrid's or some other control's Invoke/BeginInvoke method) and
replace or merge the changes into the datatable that the datagrid is bound
to.

> Hi,
>
[quoted text clipped - 19 lines]
> Thanks,
> Ben
Miha Markic [MVP C#] - 29 Nov 2004 08:15 GMT
Hi Andrew,

Yes, this is what I think, too.
One should never ever touch UI controls from within non-UI (the thread that
created them, usually the main thread)  thread.
A good article on the topic:
Safe, Simple Multithreading in Windows Forms, part 3, MSDN Online, January,
2003
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/wi
nforms01232003.asp


Signature

Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

"Andrew Smith (Infragistics)" <productmanager@infragistics.com> wrote in
message news:e4mv8gM1EHA.2112@TK2MSFTNGP15.phx.gbl...

> How is this a bug in the datagrid? Most likely the problem is that the
> fact
[quoted text clipped - 45 lines]
>> Thanks,
>> Ben

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.