Is there any way to set the datasource of a ultragrid without removing its summarize layout?
I have a ultragrid(gvResult) in my winform application.
User can select the columns and also set the sort of them in another form and then apply these changes to gvResult by pressing Apply button.
In addition gvResult must show a row counter summary.
I had to clear gvResult, like below, before applying user's changes to it, otherwise the sort of its columns had not changed to what the user had set.
gvResult.DataSource = new DataTable();gvResult.DataSource = dataTable_With_New_Set_And_Sort_of_Columns;
but this code have another problem! It removes the row counter summery too, with the other layout settings of gvResult.I searched on infragistics forum and i fined the following code, but it has the first problem, I mean the sort of the columns will remain without any changes.
BindingSource bs = new BindingSource(); bs.DataSource = typeof(DataTable); bs.DataSource = dataTable_With_New_Set_And_Sort_of_Columns; gvResult.DataSource = bs;
Do you have any suggestions?
Excuse me because of my poor english language.
I'm waiting for any suggestions......
Why no one answered?! Please help me..
Hi,
If you set the DataSource property on the grid, the grid throws away the current DisplayLayout in favor of a new layout for the new data source.
So there are a number of ways you can handle this:
1) Don't set the DataSource, but instead, change the data in the existing data source to the new data you want.
2) Save the DisplayLayout before you set the DataSource and then restore it afterward. You would do this using the grid.DisplayLayout.Save and grid.DisplayLayout.Load methods.
3) Set up your summary and other layout-related setting in the InitializeLayout event of the grid, which will fire whenever the grid's DataSource is set.
Hi mr. Saltzman, and thanks for your reply.
1) I think your first solution is not the best way for me, because the number of my columns are about 200, and if user had chosen just for example one of them to see(so i should hide 199 columns) or if he had changed the order of many of them ,maybe it takes a lot of time to change the data in the existing data source, am i right?
2) I tried this solution but it has an error when i passed a stream as parameter of Save() and Load() methods, and it did not save summery layout when i passed a filename(of a txt file) to them.
System.IO.Stream buffer = System.IO.Stream.Null;
gvResult.DisplayLayout.Save(buffer);
gvResult.DataSource = null;
null;
gvResult.DataSource = dataTable_With_New_Set_And_Sort_of_Columns;
dataTable_With_New_Set_And_Sort_of_Columns;
gvResult.DisplayLayout.Load(buffer);
< Error Message : Attempting to deserialize an empty stream. >
I think this way can be my solution but i do not know what should i pass as the parameter ?
3) I have tried this way already, but it has a problem too.You can not set the SourceColumn of your summery to a hidden column in InitializeLayout and if you do this the summary will become hidden.