467,888 Members | 1,383 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,888 developers. It's quick & easy.

[C#]fill a datagridview from a secondary thread

100+
I have one datagridview which i fill using the connected verion of ADO.NET.
When the user presses the search button a seperate thread is created and in that thead i connect to the database and fill the datagridview.


Expand|Select|Wrap|Line Numbers
  1.         private void cmdsearch_Click(object sender, EventArgs e)
  2.         {
  3.             ThreadStart t = fillthegrid;
  4.             Thread fillthread = new Thread(t);
  5.             fillthread.Start();
  6.         }
  7.  
  8.         void fillthegrid()
  9.         {
  10.             //do some stuff like disabling the search button to avoid repetitive calls
  11.             //here I connect to the database and show it in datagridview
  12.             //enabling the search button again
  13.         }
In the fillthegrid() I will have acces the button.enable property and access the the rows for writing but since the thread is not the primary I cant access it.
How to get around this problem ?

Thanks !
Oct 21 '08 #1
  • viewed: 5211
Share:
6 Replies
8TB
Create a new Thread class whose constructor takes a grid and use that.
Oct 21 '08 #2
100+
And what about the button ?
Also, since the thread is the not the one which created the Grid will I be able to access it is suspecious.
Oct 21 '08 #3
8TB
And what about the button ?
Also, since the thread is the not the one which created the Grid will I be able to access it is suspecious.
If your thread takes a grid as argument then it doesn't matter who created it. The thread should be able to work on that grid just fine.
A similar approach should suffice for the button. If the thread needs to update many more controls though then a different approach would be required.
Oct 21 '08 #4
100+
Please explain that method by an example as I need to update many controls from a secondary thread.
Oct 21 '08 #5
100+
bump ! (to get it on top again)
Oct 22 '08 #6
8TB
Please explain that method by an example as I need to update many controls from a secondary thread.
If you need to update many controls then make that thread an inner class in the class that has those controls.
Oct 22 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Dale Lundgren | last post: by
reply views Thread by saravanan_article | last post: by
6 posts views Thread by George | last post: by
3 posts views Thread by David Cartwright | last post: by
2 posts views Thread by =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.