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.Model.RowCount

In code below, I attempt to attach a DataTable to a GDBG. This grid is then used by the ExcelRW to create a worksheet. After this code runs, grid.Model.RowCount returns 0 despite the fact that there are 11 rows (grid.Model.ColCount) properly returns 2 because there are two columns. Where are my rows? They are in the datatable... GridDataBoundGrid grid = new GridDataBoundGrid() ; grid.BeginInit() ; //had to do in order for the Binder to be defined??? grid.EndInit() ; GridBoundColumn gbc = new GridBoundColumn() ; gbc.MappingName = "Name" ; gbc.HeaderText = "" ; grid.Binder.GridBoundColumns.Add(gbc) ; gbc = new GridBoundColumn() ; gbc.MappingName = "Value" ; gbc.HeaderText = "" ; grid.Binder.GridBoundColumns.Add(gbc) ; grid.DataBoundGridModel.BeginUpdate() ; grid.Binder.SuspendBinding() ; grid.Binder.DataSource = dt ; //contains 11 rows - confirmed grid.Binder.ResumeBinding() ; grid.DataBoundGridModel.EndUpdate() ;

2 Replies

DB Daniel Byers March 28, 2005 09:51 PM

This apparently affects the ColWidths collection as well?? Is this because the grid is never actually drawn?


AD Administrator Syncfusion Team March 29, 2005 04:35 AM

Yes. The colwidths sizings are not set until the grid is displayed. Likely calling grid.Refresh after the code you listed will make grid.Model.RowCount reflect the proper value, but it may not set the colwidths. If not, you can try explicitly calling: grid.AllowResizeToFit = false; grid.Model.ColWidths.ResizeToFit(GridrangeInfo.Table(), GridResizeToFitOptions.IncludeHeaders);

Loader.
Live Chat Icon For mobile
Up arrow icon