By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,678 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,678 IT Pros & Developers. It's quick & easy.

temporarily suspend datagrid databinding

P: n/a
Hi

I'm using several DataTables in my program which are updated periodically.
At the same I have those tables bound to DataGrids in my GUI. So far I've
been doing all the processing in the same program and the speed of the
processing prevented any issues when it comes to updating the GUI elements
(as DataTables are changed this triggers updates in the DataGrids), but as
soon as I add cpu time intensive processing options (i.e. receiving data
from the network rather than directly from the main thread), all hell breaks
loose because the GUI and processing threads interfere with each other. As
the link between DataTable and DataGrid is fully automatic, there's no
Control.Invoke that could be used to properly schedule GUI updates, so I'm
looking for a way to temporarily suspend updating the datagrid until the
required traffic from the net has been received and processed (and thus
resulted in updates to my DataTables). So far I have tried the following,
all without really succeeding:
- Clear the Databindings of the DataGrid, and then rebinding by setting the
DataGrid's DataSource to the respective DataTable. While clearing isn't a
problem, setting the DataSource anew triggers a System.ArgumentException
(Controls created on one thread cannot be parented to a control on a
different thread.).
- Having two DataTables for the same set of data, one for processing and one
for GUI display, and copy the content of the processing table to the display
table after processing is done. As DataTable.Clone only copies the structure
and not the content, I have to loop through the processing table and add
each row to the display table. This once again leads to undesired results as
my adding rows interferes with automatic GUI updates.
- Hide and Show the DataGrid which doesn't help either - it appears as if
the DataGrid is still updated even when it's not being shown.

That is so far all I've come up with. Any suggestions would be more than
welcome

Stephan
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Oh, and one last thing, when you get the updates over the network, you
should not be updating the dataset on the thread that gets the updates.
Rather, you should pass the information to the UI thread through a call to
Invoke, and make the changes there. This is because the grid is bound to
the dataset and will handle the events fired from the data changing on that
thread (not the UI thread).

--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Stephan Steiner" <st*****@shockfish.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi

I'm using several DataTables in my program which are updated periodically.
At the same I have those tables bound to DataGrids in my GUI. So far I've
been doing all the processing in the same program and the speed of the
processing prevented any issues when it comes to updating the GUI elements
(as DataTables are changed this triggers updates in the DataGrids), but as
soon as I add cpu time intensive processing options (i.e. receiving data
from the network rather than directly from the main thread), all hell breaks loose because the GUI and processing threads interfere with each other. As
the link between DataTable and DataGrid is fully automatic, there's no
Control.Invoke that could be used to properly schedule GUI updates, so I'm
looking for a way to temporarily suspend updating the datagrid until the
required traffic from the net has been received and processed (and thus
resulted in updates to my DataTables). So far I have tried the following,
all without really succeeding:
- Clear the Databindings of the DataGrid, and then rebinding by setting the DataGrid's DataSource to the respective DataTable. While clearing isn't a
problem, setting the DataSource anew triggers a System.ArgumentException
(Controls created on one thread cannot be parented to a control on a
different thread.).
- Having two DataTables for the same set of data, one for processing and one for GUI display, and copy the content of the processing table to the display table after processing is done. As DataTable.Clone only copies the structure and not the content, I have to loop through the processing table and add
each row to the display table. This once again leads to undesired results as my adding rows interferes with automatic GUI updates.
- Hide and Show the DataGrid which doesn't help either - it appears as if
the DataGrid is still updated even when it's not being shown.

That is so far all I've come up with. Any suggestions would be more than
welcome

Stephan

Nov 15 '05 #2

P: n/a
Nicholas

I don't understand what you mean when you say that "the link between
DataTable and DataGrid is fully automatic, there's no Control.Invoke that
could be used to properly schedule GUI updates".
Poor choice of words on my part. What I mean is that as soon as you set the
datasource of a datagrid, all changes you make to the datasource are
immediately carried over to the datagrid. So for instance if your datasource
is a datatable, editing a table cell will trigger an update of the datagrid.
I'm just guessing here, but I think that an update to the datasource
triggers a datasourcechanged event on the datagrid, and the datagrid is
redrawn. What I'd like is to temporarily suspend that mechanism, that is do
some processing on the tables (I mostly have them for internal processing,
the display is just a means to analyze how the application peforms on
various aspects and won't be available in the final release).
Oh, and one last thing, when you get the updates over the network, you
should not be updating the dataset on the thread that gets the updates.
Rather, you should pass the information to the UI thread through a call to
Invoke, and make the changes there.


I figured so much, but due to the abovementioned, I'd rather have the
processing where it belongs, not have everything pass through control.invoke
first only to trigger the processing (since the whole datagrid display part
will eventually disappear). Isn't there a way to suspend events that are
fired when the data is changed, and once there are no more incoming updates,
enable the event again and fire one to trigger the update of the datagrid?

Stephan
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.