473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

[C#]fill a datagridview from a secondary thread

153 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
6 5468
r035198x
13,262 8TB
Create a new Thread class whose constructor takes a grid and use that.
Oct 21 '08 #2
akshaycjoshi
153 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
r035198x
13,262 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
akshaycjoshi
153 100+
Please explain that method by an example as I need to update many controls from a secondary thread.
Oct 21 '08 #5
akshaycjoshi
153 100+
bump ! (to get it on top again)
Oct 22 '08 #6
r035198x
13,262 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

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

Similar topics

2
by: BG | last post by:
We're having trouble writing the code to update a UI control (label.Text) from a secondary thread. We're using C# with Windows Forms. We have a main form named MainForm, a splash screen form...
3
by: Dale Lundgren | last post by:
I have a c# class library that launches a Win Form in a secondary thread. From the Form (now running in the secondary thread) I need to be able to start a method that is defined in the class and...
0
by: saravanan_article | last post by:
Hi I am newbie to C#, i am using C# 2005 and DataGridView in my Application. The problem is described here I am using DataGrid and I placed some Headers like Column1,Column2,Column3.... What i...
1
by: George | last post by:
Hi, I have a DataGridView, bounded to a DataTable which is populated/updated by a OleDbDataAdapter (with OleDbConnection) to an Access Database. (Sounds familiar to some of you ... I have...
6
by: George | last post by:
Hi, I have been encountering a refresh problem with DataGridView, which is bound to a DataTable. When I make updates (Add, Delete, update) to the DataGridView, everything flow nicely to...
3
by: David Cartwright | last post by:
Hi all, I'm having a weird time with a call to the Refresh() method of a DataGridView. I have a VB.NET 2005 Windows application with a main form and a "worker" thread. The main form delegates a...
2
by: Adrien Reboisson | last post by:
I'm trying to build a basic DB explorer using C# & Visual Studio 2005. I installed SQL Server 2005 Express, created a blank project, dropped a TreeView, a ListView and a DataGridView : DB objects...
4
by: shibeta | last post by:
Hello, I have problem with DataGridView and BindingSource. I have created DataSet and added TableData to it with manualy created columns (without DataAdapter - I'm not using MSSQL). On the Form I...
2
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
The auto-generated line of code to fill a DataGridView once it is placed on the designer surface in VS2005 is typically: this.xyzTableAdapter.Fill(this.myDataSet.MyMember); But if the query...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.