We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

changing datasource at runtime without rebuilding entire grid columns when datasources have some columns in common

I am building a highly dynamic grid using the ggc.

The grid is to be dynamically bound to the two datatables. I want to use one ggc to accomplish this.

The data looks like this ...

datatable1 => id, name, rate, week1, week2, week3
datatable2 => id, name, rate, week4, week5, week6, week7
datatable2 => id, name, rate, week8, week9

The id, name, and rate columns for the two datatable have the same datatypes.
The week columns (week1, week4, ect) is dynamic and is different between the two datatables).

I want to rebind the grid at runtime to a a specific datatable based on the selection from a combo box.

How can I accomplish this without dynamically rebuilding the entire grid over again when I change datasource?
Can I reuse the id, name, and rate columns between the datatables since they are the same and only re-contruct the week columns?
Is there an easy way to save conditional formats and other formatting info between each datatables views so that I do not lose them?
How can I just show the id, name and week1...9 columns and NOT show the rate column (do I bind the datasource before I remove the columns or is it the other way around)?

1 Reply

AD Administrator Syncfusion Team November 28, 2006 09:52 AM UTC

Hi James,

You can add UnBoundFieldDescriptor for the columns that you want to dynamically change from either table to the grid. Then make one table the grid’s datasource and use .QueryValue event to dynamically provide the values from the other table. If you want to handle editing, you would also have to handle SaveValue event.

this.gridGroupingControl1.TableDescriptor.UnboundFields.Add("TableColumnTwo0");
this.gridGroupingControl1.TableDescriptor.UnboundFields.Add("TableColumnTwo1");
this.gridGroupingControl1.TableDescriptor.UnboundFields.Add("TableColumnTwo2");

//Used for saving/Editing the data in the filed.
private void gridGroupingControl1_SaveValue(object sender, FieldValueEventArgs e)
{
GridTable table = this.gridGroupingControl1.GetTable(e.TableDescriptor.Name);
int iRecordIndex = table.UnsortedRecords.IndexOf(e.Record);
string sColumnName = e.Field.Name;
table2.Rows[iRecordIndex][sColumnName] = e.Value;
}

//For display purpose....
private void gridGroupingControl1_QueryValue(object sender, FieldValueEventArgs e)
{
GridTable table = this.gridGroupingControl1.GetTable(e.TableDescriptor.Name);
int iRecordIndex = table.UnsortedRecords.IndexOf(e.Record);
string sColumnName = e.Field.Name;
e.Value = table2.Rows[iRecordIndex][sColumnName];
}

Please refer the sample for implementation.
CombineTables.zip

Best Regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon