Fill DataGridView After particular time interval

Posted by Ruchir under C# on 5/28/2009 | Views : 7503 | Status : [Member] | Replies : 3
Dear Friends
i want to fill datagrid in c#.net after particular time interval...so i make one function which is simply fire "select" query on table and fill grid, and i call this function using timer...Here in the below code FillGrid is function which has simple select query based on some condition and it fill grid value after every 10 seconds....

System.Timers.Timer Mtm = new System.Timers.Timer();
Mtm.Elapsed += new ElapsedEventHandler(FillGrid);
Mtm.Interval = 10000;
Mtm.Start();


private void FillGrid(object source, ElapsedEventArgs e)
{

string Query = "select * from reservation where status = 0";

SqlDataAdapter dataAdp = new SqlDataAdapter(Query, cnn);
DataSet ds = new DataSet();
dataAdp.Fill(ds, "Reservationdata");

tab1.Controls.Add(dataGridView);

dataGridView.DataSource = ds.Tables["Reservationdata"].DefaultView;
}

while Refreshing Fill DataGridView After particular time interval using timer in C#.net i got an exception.
The Exception is - "Cross-thread operation not valid: Control tab1 accessed from a thread other than the thread it was created on."


if u have any other idea to refresh a datagrid then plz tell me....

Please Help me.....i need ur help..
Thank you.


Ruchir.




Responses

Posted by: Vuyiswamb on: 5/28/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Is your Application a Windows Application or a Web Application ?

Thank you for posting at Dotnetfunda
[Administrator]

Ruchir, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ruchir on: 5/28/2009 [Member] Starter

Up
0
Down
mine is windows application..


Ruchir, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 5/28/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Good Morning Ruchir.

You can use a Windows Service to do that or look how i used threads to kill a Process after every 5 seconds.

http://www.dotnetfunda.com/articles/article191.aspx

Thank you for using DotnetFunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Ruchir, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response