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

GDBG-Column does not show in Grid after adding new column in DataTable

I found this problem under the situation when prior to adding the new column in tha DataTable, I move the column order in the grid by dragging the column. This error can be reproduced from the Filter Bar sample. I added a new button to create a new column as below : private void button4_Click(object sender, System.EventArgs e) { // Add Column ds.Tables[0].Columns.Add(new DataColumn("NEW COL",typeof(string))); } Before clicking the button, try to move the order in the grid. Then click the button, the new column does not appear in the grid. If the column order is not changed prior to clicking the button, there is no issue then. Any idea how to avoid this problem ?

4 Replies

AD Administrator Syncfusion Team April 26, 2005 03:40 PM UTC

Maybe you have to reset the datasource after adding the new column to the grid. this.grid.BeginUpdate(); this.grid.DataSource = null this.grid.Model.ResetVolatileData(); // add the column this.grid.DataSource = your datasource; this.grid.Binder.InitializeColumns(); this.grid.EndUpdate(); That the way how I would like to handle this. Regards, Thomas


PE Pua Eng Heng April 27, 2005 01:24 AM UTC

Hi Tomas, Rebinding the grid does not help in this case. To avoid the probem, I have to recreate the grid on run-time. Like : this.gridRecordNavigationControl1 = new Syncfusion.Windows.Forms.Grid.GridRecordNavigationControl(); this.gridRecordNavigationControl1.Location = new System.Drawing.Point(32, 48); this.gridRecordNavigationControl1.MaxLabel = "of 1000"; this.gridRecordNavigationControl1.MaxRecord = 1000; this.gridRecordNavigationControl1.NavigationBarWidth = 237; this.gridRecordNavigationControl1.Size = new System.Drawing.Size(520, 256); this.gridRecordNavigationControl1.SplitBars = Syncfusion.Windows.Forms.DynamicSplitBars.Both; this.gridDataBoundGrid1 = new Syncfusion.Windows.Forms.Grid.GridDataBoundGrid(); this.gridDataBoundGrid1.DataSource=this.dataSet11.Customers; this.gridDataBoundGrid1.VerticalScrollTips=true; this.gridDataBoundGrid1.UseListChangedEvent = true; this.gridRecordNavigationControl1.Controls.Add(this.gridDataBoundGrid1); //Add the nav control to the form. this.Controls.Add(this.gridRecordNavigationControl1); this.gridDataBoundGrid1.Model.ColWidths.ResizeToFit(GridRangeInfo.Row(0)); This will certainly work. But I really hope to see a simpler solution. Regards Pua Eng Heng. >Maybe you have to reset the datasource after adding the new column to the grid. > >this.grid.BeginUpdate(); > >this.grid.DataSource = null > >this.grid.Model.ResetVolatileData(); > >// add the column >this.grid.DataSource = your datasource; >this.grid.Binder.InitializeColumns(); > >this.grid.EndUpdate(); > >That the way how I would like to handle this. > >Regards, >Thomas


AD Administrator Syncfusion Team April 28, 2005 09:37 PM UTC

Hi Pua, try this code: private void button4_Click(object sender, System.EventArgs e) { GridBoundColumnsCollection columns; if (gridDataBoundGrid1.Binder.GridBoundColumns.Count == 0) columns = (GridBoundColumnsCollection) this.gridDataBoundGrid1.Binder.InternalColumns.Clone(); else columns = (GridBoundColumnsCollection) gridDataBoundGrid1.Binder.GridBoundColumns.Clone(); // Add Column ds.Tables[0].Columns.Add(new DataColumn("NEW COL",typeof(string))); GridBoundColumn newColumn = new GridBoundColumn(); newColumn.MappingName = "NEW COL"; columns.Add(newColumn); this.gridDataBoundGrid1.Binder.GridBoundColumns = columns; } This works fine then with 3.2.1.0 but I haven''t tried earlier versions. Stefan >Hi Tomas, > >Rebinding the grid does not help in this case. To avoid the probem, I have to recreate the grid on run-time. Like : > >this.gridRecordNavigationControl1 = new Syncfusion.Windows.Forms.Grid.GridRecordNavigationControl(); > this.gridRecordNavigationControl1.Location = new System.Drawing.Point(32, 48); > this.gridRecordNavigationControl1.MaxLabel = "of 1000"; > this.gridRecordNavigationControl1.MaxRecord = 1000; > this.gridRecordNavigationControl1.NavigationBarWidth = 237; > this.gridRecordNavigationControl1.Size = new System.Drawing.Size(520, 256); > this.gridRecordNavigationControl1.SplitBars = Syncfusion.Windows.Forms.DynamicSplitBars.Both; > >this.gridDataBoundGrid1 = new Syncfusion.Windows.Forms.Grid.GridDataBoundGrid(); > this.gridDataBoundGrid1.DataSource=this.dataSet11.Customers; > this.gridDataBoundGrid1.VerticalScrollTips=true; > this.gridDataBoundGrid1.UseListChangedEvent = true; > this.gridRecordNavigationControl1.Controls.Add(this.gridDataBoundGrid1); > >//Add the nav control to the form. >this.Controls.Add(this.gridRecordNavigationControl1); > this.gridDataBoundGrid1.Model.ColWidths.ResizeToFit(GridRangeInfo.Row(0)); > >This will certainly work. But I really hope to see a simpler solution. > >Regards >Pua Eng Heng. > > > > >>Maybe you have to reset the datasource after adding the new column to the grid. >> >>this.grid.BeginUpdate(); >> >>this.grid.DataSource = null >> >>this.grid.Model.ResetVolatileData(); >> >>// add the column >>this.grid.DataSource = your datasource; >>this.grid.Binder.InitializeColumns(); >> >>this.grid.EndUpdate(); >> >>That the way how I would like to handle this. >> >>Regards, >>Thomas


AD Administrator Syncfusion Team April 29, 2005 11:57 AM UTC

This works. Thanks very much. Regards Pua Eng Heng. >Hi Pua, > >try this code: > > > private void button4_Click(object sender, System.EventArgs e) > { > GridBoundColumnsCollection columns; > if (gridDataBoundGrid1.Binder.GridBoundColumns.Count == 0) > columns = (GridBoundColumnsCollection) this.gridDataBoundGrid1.Binder.InternalColumns.Clone(); > else > columns = (GridBoundColumnsCollection) gridDataBoundGrid1.Binder.GridBoundColumns.Clone(); > > // Add Column > ds.Tables[0].Columns.Add(new DataColumn("NEW COL",typeof(string))); > > GridBoundColumn newColumn = new GridBoundColumn(); > newColumn.MappingName = "NEW COL"; > columns.Add(newColumn); > this.gridDataBoundGrid1.Binder.GridBoundColumns = columns; > } > > >This works fine then with 3.2.1.0 but I haven''t tried earlier versions. > >Stefan > > >>Hi Tomas, >> >>Rebinding the grid does not help in this case. To avoid the probem, I have to recreate the grid on run-time. Like : >> >>this.gridRecordNavigationControl1 = new Syncfusion.Windows.Forms.Grid.GridRecordNavigationControl(); >> this.gridRecordNavigationControl1.Location = new System.Drawing.Point(32, 48); >> this.gridRecordNavigationControl1.MaxLabel = "of 1000"; >> this.gridRecordNavigationControl1.MaxRecord = 1000; >> this.gridRecordNavigationControl1.NavigationBarWidth = 237; >> this.gridRecordNavigationControl1.Size = new System.Drawing.Size(520, 256); >> this.gridRecordNavigationControl1.SplitBars = Syncfusion.Windows.Forms.DynamicSplitBars.Both; >> >>this.gridDataBoundGrid1 = new Syncfusion.Windows.Forms.Grid.GridDataBoundGrid(); >> this.gridDataBoundGrid1.DataSource=this.dataSet11.Customers; >> this.gridDataBoundGrid1.VerticalScrollTips=true; >> this.gridDataBoundGrid1.UseListChangedEvent = true; >> this.gridRecordNavigationControl1.Controls.Add(this.gridDataBoundGrid1); >> >>//Add the nav control to the form. >>this.Controls.Add(this.gridRecordNavigationControl1); >> this.gridDataBoundGrid1.Model.ColWidths.ResizeToFit(GridRangeInfo.Row(0)); >> >>This will certainly work. But I really hope to see a simpler solution. >> >>Regards >>Pua Eng Heng. >> >> >> >> >>>Maybe you have to reset the datasource after adding the new column to the grid. >>> >>>this.grid.BeginUpdate(); >>> >>>this.grid.DataSource = null >>> >>>this.grid.Model.ResetVolatileData(); >>> >>>// add the column >>>this.grid.DataSource = your datasource; >>>this.grid.Binder.InitializeColumns(); >>> >>>this.grid.EndUpdate(); >>> >>>That the way how I would like to handle this. >>> >>>Regards, >>>Thomas

Loader.
Live Chat Icon For mobile
Up arrow icon