Hi,
I'm trying to usa an UltraWinGrid to display dynamic data.
I've binded the UltraWinGrid with a BindingSource object. The datasource of this object changes (only rows change, not columns).
If I try this:
binding.DataSource = _myData; myWinGrid.DataBind();
I can correctly load data in the control, but the row layout I've applied with the designer resets to a default, flat, "all columns" layout.
How can I keep the layout and dynamically change the data? I've tried to save the layout but I was not able to load it at runtime...
Thanks in advance
What excatly is changing? If the structure of the data source is changing, then there's no way the grid can maintain the layout, because the columns in the original layout do not exist in the new data structure.
It sounds like this is probably the case, because that's the only reason why loading the saved layout would fail - if the current data structure in the grid doesn't match the structure in the layout.
Hi Mike,
Thanks a lot for your response.
I verified your suggestion and I report the result since it's not working yet:
- I use a BindingSource as DataSource wich binds to a DataTable
- to get the data in the DataTable I use a TableAdapter wich executes a stored procedure on SQL Server
- the result set is always made of 20 columns that have always the same names and data types
In the row layout designer I have the 20 columns. If I watch my DataTable at runtime I have the same 20 columns, so it seems that nothing is really changing other than the object instance itself.
I notice also this strange behaviour, that can help to find a solution:
- if I set the DataSource while the control is not yet rendered (it is in a page of a tab control) but i don't call DataBind() when i activate the control I see my synchronized (as in the DataTable runtime object) and well formatted rows (as in the row layout designer)
- if I set the DataSource while the control is visible (the tab page is active) and I don't call DataBind() it doesn't refresh data
- if I set the DataSource and call DataBind() the layout is resetted to flat grid
I've also tried to save a layout. I'm able to load it at design time (with the ultragrid designer) but I wasn't able to write the proper code to load it at runtime. Is there such code?
Thanks.
It sounds to me like you are changing the BindingSource's DataSource, but that you are still binding the grid to the same BindingSource object. This might mean that when you set the DataSource on the grid, nothing happens, because you are setting it to the same object. If that's the case, then all you need to do in the grid is call grid.Rows.Refresh(ReloadData) instead of calling DataBind. This will tell the grid to reload the data without losing the data structure.
The only other thing that comes to mind is that if the column names and types are not changing, maybe the name of the tables are changing and that's what is causing the loss of the layout.
Hi again Mike,
thank you for your useful replies.
I've tried to follow your suggestions but the matter doesn't resolve.
It's correct: I'm changing the BindingSource's DataSource but I'm still binding the grid to the same BindingSource object.
I've replaced the DataBind() with grid.Rows.Refresh(ReloadData), with no luck.
I made some more attempts:
- used a brand new ultragrid without any other choice than the selection of hidden columns (no row layout designer used) => it loses my choices (I see all columns)
- since in my app I'm trying to use the same grid to display 4 query results with the same schema I've tried to hardcode the loading of these results (onLoad event in the form) only for debugging purposes => the results are shown correctly and the layout is preserved (so, only when I change the result set at runtime the grid loses the choice I made in the column arrangement)
Thanks again for your help.
Well, I'm not sure, then. If you can create a small sample project demonstrating thep problem, you can Submit an incident to Infragistics Developer Support and they should be able to tell you why it's not working.
Saving and loading the layout should work, assuming that all of the Band and column keys are the same and the data types of all of the columns are the same. If that's not working, then it's a bug. But I am pretty sure it works, so something must be changing in the data structure. Or else the loading of the layout is called before the data source has been set.
I finally solved this issue with this workaround:
1. In the UG Designer manually define the schema with all the columns in my procedure
2. Tell the UG Designer that I will manually assign the DataSource property (not use BindingSource nor UltraDataSource)
3. In the refresh method (where I run the query and previously rebinded the BindigSource binded to the UG) I manually assign the DataSource property with the query result
With this, my layout is preserved and I get the desired behaviour (all desired columns well formatted and no extra columns)
I've not digged into this BindingSource problem; initially I thought its beaviour behind the scenes should be approximately as I described above; I can't tell why it is different.
Thanks again Mike.
Bye.