GDBG LayoutColumns does not recreate column descriptors

We are trying to create the code that modifies what columns are visible in GDBG based on the circumstances. To change the layout we use LayoutColumns(string [] {}) method.

It works fine first time (we hide a few columns)
Then when the second time we show some of the previously hidden columns, they appear empty and without column descriptors.

The only workaround we've found was to reapply grid DataSource, or rather recreate GridBoundColumns manually, since we have a lot of columns that are not data bound.

Is there a better way? Recreating columns from scratch is very inconvenient.

We tried this in .NET 1.1 (SF 3.0) and .NET 3.5 (SF 8.1)

Thanks.

DataTable table = new DataTable();
table.Columns.Add("A");
table.Columns.Add("B");
table.Columns.Add("C");
table.Rows.Add(new object [] {"A1", "B1", "C1"});
table.Rows.Add(new object [] {"A2", "B2", "C2"});
table.Rows.Add(new object [] {"A3", "B3", "C3"});

gridDataBoundGrid1.DataSource = table.DefaultView;

Syncfusion.Windows.Forms.Grid.GridHierarchyLevel hl = gridDataBoundGrid1.Binder.GetHierarchyLevel(0);

hl.LayoutColumns(new string[] {"A"});
hl.LayoutColumns(new string[] {"A", "B", "C"});

1 Reply

CI Christopher Issac Sunder K Syncfusion Team May 26, 2010 03:51 AM UTC

Hi Jeck,

Thank you for your interest in Syncfusion products.
Regret for the delay. Please try using GridBoundColumns collection in GridDataBoundGrid to Show/Hide columns instead of LayoutColumns.


GridBoundColumnsCollection coll;
coll = this.gridDataBoundGrid1.Binder.InternalColumns.Clone() as GridBoundColumnsCollection;

//hiding columns
GridBoundColumnsCollection cool = coll.Clone() as GridBoundColumnsCollection;
cool.RemoveAt(2);
cool.RemoveAt(1);
this.gridDataBoundGrid1.GridBoundColumns = cool;

//showing columns
this.gridDataBoundGrid1.GridBoundColumns = coll;


Please refer the following sample which illustrates the above behavior in GridDataBoundGrid.

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=MasterDetailHide1705156286.zip

Let me know if you need any further clarifications.

Regards,
Christopher K.

Loader.
Up arrow icon