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

GridDataBoundGrid - adding and deleting columns

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 !

3 Replies

AD Administrator Syncfusion Team 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


RY Rob Yang 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 ?


AD Administrator Syncfusion Team 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

Loader.
Live Chat Icon For mobile
Up arrow icon