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.
Unfortunately, activation email could not send to your email. Please try again.

Add Column

Thread ID:

Created:

Updated:

Platform:

Replies:

47074 Jul 27,2006 09:56 AM Jul 31,2006 12:28 AM Windows Forms 4
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On July 27, 2006 09:56 AM

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

Administrator [Syncfusion]
Replied On July 28, 2006 02:09 AM

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

Administrator [Syncfusion]
Replied On July 28, 2006 06:05 AM

Thank you very much - this works fine

Administrator [Syncfusion]
Replied On July 28, 2006 10:32 AM

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

Administrator [Syncfusion]
Replied On July 31, 2006 12:28 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;