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
close icon

Force a Grid to be 2x2

I''m trying to change the size of a grid to a single cell (ncluding row/col borders) if there is no data, but it isn''t working. What is wrong with this code (what am I missing) : if (numDefects == 0) { this.gridCtl.BeginUpdate(); int [,] grid = new int[2, 2]; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) grid[i,j] = 0; this.gridCtl.Model.PopulateValues( GridRangeInfo.Cells(0, 0, 2, 2), grid ); this.gridCtl.EndUpdate(); this.gridCtl.Refresh(); this.gridCtl.Invalidate(); return; }

1 Reply

AD Administrator Syncfusion Team June 29, 2006 09:33 PM UTC

Hi Michael, The Populate method gives you an easy way to copy the data from any given datasource that implements the IList interface or is an Array to the specified range of cells in the Grid. It doesn''t configure the grid (ie it doesn''t set the RowCount/ColCount/Style property of the grid). If you want to configure the grid, you can set those property explictly. Here is a code snippet. if (numDefects == 0) { this.gridCtl.BeginUpdate(); int [,] grid = new int[2, 2]; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) grid[i,j] = 0; this.gridCtl.Model.PopulateValues( GridRangeInfo.Cells(0, 0, 2, 2), grid ); //Set the RowCount AND Colcount this.gridCtl.RowCount = 1; this.gridCtl.ColCount = 1; this.gridCtl.EndUpdate(); this.gridCtl.Refresh(); this.gridCtl.Invalidate(); return; } Let me know if this helps, Best Regards, Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon