470,815 Members | 1,300 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

How to acces datagrid from other thread

Hi.
Iam trying to make it work:

My application receives data from RS port by the DataReceived event. Then
this event is accesing dataGridview, but when i have some errors connected
with accesing this datagrid. Sometimes it works properly, sometimes not.

For any help thanks
Here is sample code:

void rs_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
string t = rs.ReadLine(); t = t.Remove(t.Length - 1);
string temp = configFile.getParameter("b" + t);

if (temp == null)
{
if (MessageBox.Show("Button is not recognized. Would you
like to add function to this button?", "New Button detected",
MessageBoxButtons.YesNo,
MessageBoxIcon.Information) == DialogResult.Yes)
{
Form2 form2 = new Form2();
form2.Button = "b" + t;

if (form2.ShowDialog() != DialogResult.Cancel)
{
//System.Threading.Thread.Sleep(500);
Fill_DataGrid();
}
}
.........
}
May 21 '06 #1
1 1117
Użytkownik "PiotrKolodziej" <pi*************@gmail.com> napisał w wiadomo¶ci
news:ae**************************@news.chello.pl.. .
Hi.
Iam trying to make it work:

My application receives data from RS port by the DataReceived event. Then
this event is accesing dataGridview, but when i have some errors connected
with accesing this datagrid. Sometimes it works properly, sometimes not.


Use BeginInvoke or Invoke to fill DataGrid on GUI thread, for example:

delegate void myDelegate();
private void rs_DataReceived(...)
{
...
// fill data grid on form2
form2.BeginInvoke(new myDelegate(Fill_DataGrid),
new object[]{data});
}

private void Fill_DataGrid()
{
...
}

Grzegorz

ps. why not alt.pl.comp.lang.csharp?

May 22 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Stephan Steiner | last post: by
13 posts views Thread by pmcguire | last post: by
2 posts views Thread by TFS | last post: by
9 posts views Thread by rn5a | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.