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. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridDataBoundGrid - adding and deleting columns

Thread ID:

Created:

Updated:

Platform:

Replies:

57477 Mar 5,2007 06:46 PM UTC Mar 6,2007 11:26 PM UTC WinForms 3
loading
Tags: GridControl
Rob Yang
Asked On March 5, 2007 06:46 PM UTC

Hi - we are using a GridDataBoundGrid, with certain columns containing a custom treeview cell type with checkboxes (we opened a Direct-Trac incident to resolve the treeview issue, thanks !)

Part of the requirement is to be able to dynamically add and remove columns. One thing we are finding however is that after a column is removed and then re-added (same name, cell model, etc), the CellText / ControlText property of the column does not seem to work (it always comes back with an empty string).

Before going further I wanted to ask if there is a recommended procedure for removing and then re-adding columns to a GDBG. The GDBG control's DataSource is set to a typed DataTable.

To add a column we are creating a new GridBoundColumn object, and using GridBoundColumns.Add(), then calling the DataTable.Columns.Add(). To remove the column we use GridBoundColumns.Remove() and then DataTable.Columns.Remove()

(we also add/remove the custom cell model type, but that doesn't seem related .. or does it ?)

Thanks for any assistance !

Administrator [Syncfusion]
Replied On March 5, 2007 07:44 PM UTC

Hi Rob,

Use the GridBoundColumns property to manages the bound columns in a GridDataBoundGrid. Here is a code snippet.

//Clear the All columns bound to grid...
this.gridDataBoundGrid1.GridBoundColumns.Clear();

//Add the new column to display in a grid.
GridBoundColumn EmpName = new GridBoundColumn();
EmpName.MappingName = "ColumnName";
this.gridDataBoundGrid1.GridBoundColumns.Add(EmpName);

//Remove a new Column......
this.gridDataBoundGrid1.GridBoundColumns.Remove(EmpName);
this.gridDataBoundGrid1.GridBoundColumns.RemoveAt(1);

this.gridDataBoundGrid1.DataSource = ds.Tables[0];

Sample : GDBGSingleColumn.zip

Best regards,
Haneef

Rob Yang
Replied On March 5, 2007 11:45 PM UTC

Thanks Haneef. The difference between your code snippets and what we are doing is that the initial columns (let's call them A, B, and C) are set up in the designer, as is the data source.

Let's say at run time the user clicks a checkbox elsewhere in the UI and as a response we add columns D and E to both the GDBG and the data table.

Later on, the user unclicks that checkbox, so we then remove them.

Are there any known issues or gotchas we should be aware of ?

Administrator [Syncfusion]
Replied On March 6, 2007 11:26 PM UTC

Hi Rob,

The attached sample shows you "How to add/remove the column from the grid and its underlying datasource?". It also implements the Cols.Hidden property to hide/show column from the grid. Please test the attached sample and let me know if this serves.

Sample : DataBoundRemoveColumn.zip

Best regards,
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.

Warning Icon 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.Close Icon

;