Hi,
I have a wingrid that uses row layout and there is a thread that runs behind (Basically a timer). I'll refresh the data in the grid every 1000 msec. based on the thread. Since row layout is used, after couple of refreshes' the layout is going for a toss. How to reset the rowlayout.? Tried with ResetRowLayout, but in vain..I have this row layout in initializelayout event.
In simple words, i have to refresh the grid data being displayed. I have to hit the db and bind the values again.
Any help is appreciated.
It really depends on what your data source is what you mean by "refresh the grid".
If your data is changing then you just need to update the data source with the changes. If your data source is an IBindingList, it will notify the grid of the changes and that's it.
If you are doing something to your data source which is causing it to send a reset notification, then the grid has no choice but to throw away the current layout and start over. In which case, you can just save and restore the layout.
Mike,
I want to refresh the grid every 5 minutes. As said earlier, threading is one such approach which now i understand is 'dangerous'. It makes that much difficult to refresh the grid using a Timer as i have row set layouts in grid's initialize layout event and the origin x,y gets disturbed each time the datasource is set.
Pls suggest the best way to refresh the grid..
To restore the grid to it's initial state I store the serialized layout data in my form and restore when needed.
Martin
MemoryStream initialGridLayout;
void form_load() {
initialGridLayout = new MemoryStream(); grid.DisplayLayout.Save(initialGridLayout, PropertyCategories.All);}
void RestoreGridLayout() {
initialGridLayout.Seek(0, SeekOrigin.Begin); grid.DisplayLayout.Load(initialGridLayout);
}
I'm not sure I understand your question.
It sounds like maybe you need to save the DisplayLayout of the grid and then re-load it.
But even if that works, it sounds like what you are doing is extremely dangerous. If you are modifying the data source that the grid is bound to on another thread, this will almost certainly cause problems. The grid is not multi-thread safe, nor is the BindingManager. The grid or the DotNet Bindingmanager could, at any time, ask for the value of a cell or some other property setting from the data source, and if that data source is in the middle of being modified on a different thread, it could cause your application to crash or your data to become corrupted. Not only will this almost certainly cause problems, the problem will be nrealy impossible to track down, since it will occur on a different thread.