Add Column

Hello,

our gridgrouping control is bound to a dataset. Now I don''t know how to add a new column to the grid programmatically. I want to put a button on the form and when the user clicks the button a new column should be added (perhaps with a dialog to enter a column name etc.)

But I don''t now how to add a column (to the grid and the underlying dataset) programmatically?

Any help would be great

4 Replies

AD Administrator Syncfusion Team July 28, 2006 06:09 AM UTC

Hi,

You can use the below code snippet to add the column in a grid.

this.gridGroupingControl1.BeginUpdate();
this.gridGroupingControl1.ResetTableDescriptor();

DataTable dt = this.gridGroupingControl1.DataSource as DataTable;
dt.Columns.Add("ID");

this.gridGroupingControl1.EndUpdate(true);
this.gridGroupingControl1.Reinitialize();

Let me know if this helps.
Best Regards,
Haneef


AD Administrator Syncfusion Team July 28, 2006 10:05 AM UTC

Thank you very much - this works fine


AD Administrator Syncfusion Team July 28, 2006 02:32 PM UTC

Sorry i was too fast with my answer. I have attached a sample where you can see a strange behavior. When you click on the button to add a new column the whole gridview is empty. Furthermore I think I would loose my whole column formating with the ResetTableDescriptor call. Can you take a look at the sample.

(Hope it''s Ok i found the sample in the forum and modified it a little bit so show my problems)

GGC_4tablesColumnAdd.zip


AD Administrator Syncfusion Team July 31, 2006 04:28 AM UTC

Hi,

Use this code snippet to add the columns in a grid.

gridGroupingControl1.BeginUpdate();

DataSet ds = gridGroupingControl1.DataSource as DataSet;
DataTable test = ds.Tables[0];

gridGroupingControl1.GetTableDescriptor(test.TableName).Columns.Add("ID", "ID");
test.Columns.Add("ID");

gridGroupingControl1.EndUpdate(true);
gridGroupingControl1.Reinitialize();

Thanks,
Haneef

Loader.
Up arrow icon