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

Virtual Grid with default column widths

I am using the virtual grid and would like to set the "initial" sizes for each column. (Note: not all columns will be the same width) Then, during runtime the app needs to be able to let the user size them as he/she wishes.. The problem I am seeing is that GetColSize(..) basically forces a column to that size and doesn t allow dynamic sizing. So in short, one school of thought might be to kill off the GetColSize(..) call and just set this information when the grid is initialized, but how do you do this? Other ideas?

5 Replies

AD Administrator Syncfusion Team March 8, 2004 06:55 AM UTC

If you can use a ''half'' virtual grid (ie. explicitly setting grid.ColCount = xxxx, only providing rowcount through QueryRowCount, and not providing colcount through QueryColCount), then you could just explicitly set grid.ColWidth[nCol] = yy for each column. If you do this, then the user would be able to size the grid columns without further work on your part, and you could set explicit initial sizes. This would assume your datasource had relatively few columns and the only need for the virtual grid was with respect to having many rows (or some other reason not pertaining to columns). If your grid has too many columns to allow the explicit setting of ColCount, then the next suggestion would be to create a hashtable with keys being a column index and values being the size. Then add your explicitly sized columns to this hashtable. Then handle the QueryColWidth event. In the handler, check whether e.Index is a key in your hashtable. If so, then get the width value from the hashtable, and set e.Size to this value (also setting e.Handled). This will take care of the initial sizing. To support user resizing, you would catch the ColWidthsChanged event, and in your handler, get the columns changing from the events args, check if they are in your hashtable. If so, then set the new width to the existing key in the hashtable. If not, then add the colindex and value to the table.

MB Matthew Brohn March 11, 2004 05:49 PM UTC

Ok I gave this a whirl.. private void gridControl1_ColWidthsChanged(object sender, GridRowColSizeChangedEventArgs e) { for (int ix = e.From; ix <= e.To; ix++) { GridModelRowColSizeIndexer myIndexer = this.gridControl1.ColWidths; m_ColumnSize[ix] = myIndexer.Dictionary[ix]; } } and then simply accessed m_ColumnSize in gridControl1_QueryColWidth(..) and it kindof works although the columns paint seems to b messed up. I can give you a sample.. Or is there a better what to store off the changed column widths? Thanks!

AD Administrator Syncfusion Team March 11, 2004 06:12 PM UTC

I think you will need to use ColWidthsChanging as you can get the size from the args. Try this code in ColWidthsChanging. The e.Cancel = true is to prevent the size from being put into grid.ColWidths which you do not want to do in a virtual grid. The Refresh call is to redraw things so the QueryColWidth is hot and has a chance of returing the new colwidth stored in m_ColumnSize. for (int ix = e.From; ix <= e.To; ix++) { m_ColumnSize[ix] = e.Values[ix - e.From]; e.Cancel = true; this.Refresh(); }

AD Administrator Syncfusion Team March 11, 2004 07:15 PM UTC

hmm no go.. still get a wierd colun header redraw issue.. I looks like the headers are confused about where to draw. Do you want me to post a sample?

AD Administrator Syncfusion Team March 11, 2004 09:05 PM UTC

The this.Refresh() should read this.grid.Refresh(). I was using a derived grid when I checked out the code, so this.Refresh() referred to calling Refresh on the grid. This should handle the drawing problems on the header. Here is the sample I worked with. VirtDnDSample-1_967.zip

Live Chat Icon For mobile
Up arrow icon