Hi
I have a network program that fills 4 datatables while receiving data bursts
and which should then show those tables in 4 datagrids. The main GUI class
contains event callbacks for events that the receiver thread throws when
it's being activated and deactivated (handler_BroadcastStart, and
handler_EndOfBroadcast):
private void handler_BroadcastStart()
{
options.receiverActive = true;
options.Invoke(new EventHandler(options.updateGUI));
this.receiverActive = true;
this.dataGrid1.Invoke(new EventHandler(updateGUI));
Application.DoEvents();
}
private void handler_EndOfBroadcast()
{
options.receiverActive = false;
options.Invoke(new EventHandler(options.updateGUI));
this.receiverActive = false;
this.dataGrid1.Invoke(new EventHandler(updateGUI));
Application.DoEvents();
}
The main GUI form contains one datagrid, which is bound and unbound to the
datasource (I've tried suspending databindings several times in vain.. maybe
you've some of my other posts to these newsgroups). Here's the code I use
to show the data when the receiver is not active.
public void updateGUI(object sender, EventArgs e)
{
if (this.receiverActive)
dataGrid1.DataSource = null;
else
this.display(handler.manager.getRecords());
}
public void display(DataTable table)
{
this.table = table;
view = new DataView(this.table, "", "ID ASC",
DataViewRowState.CurrentRows);
this.dataGrid1.DataSource = view;
}
This works just as it should. Now my form to display several options (called
options) contains the other three Datagrids and I try to activate and
deactivate them using a very similar mechanism. You've already seen the
option.Invoke call above, and here's the updateGUI method of the options
form:
public void updateGUI(object sender, EventArgs e)
{
if (this.receiverActive)
{
dataGrid1.DataSource = null;
dataGrid2.DataSource = null;
dataGrid3.DataSource = null;
}
else
{
this.dataGrid1.DataSource = new DataView(stats.packetsReceived, "", "seqNo
ASC",
DataViewRowState.CurrentRows);
this.dataGrid2.DataSource = new DataView(stats.missingPackets, "", "ID
ASC",
DataViewRowState.CurrentRows);
this.dataGrid3.DataSource = stats.completionPercentages;
this.update();
}
}
The problem is, nulling the DataSource works, but binding it again locks up
the GUI. The program is still running, but neither the main GUI form, nor
the options form are accessible anymore and I have to kill them via the task
manager. I've also tried to call Invoke on the 3 datagrids in the options
form directly, without any success, as well as manipulating the DataSource
of those 3 datagrids in the UpdateGUI method of the main GUI class.. all
without success. Any ideas how I can handle those 3 datagrids in my 2nd form
just like the main datagrid?
Regards
Stephan Steiner