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

Autosizing grid columns to fit available space

I tracked down some information on column sizing but wasn''t able to find anything specific to what I''m trying to do here. I have some GDBGs which live in XPTaskBarBoxes (within child panel) and would like the Grid to fill all avilable space (width) regardless of the number of columns in the grid. For example, one grid has four columns, but overall it only takes up about 1/2 of the available width in the TaskBarBox. I have the child Panel set to the full width of the TaskBarBox and the Grid is also set to the full width (also tried dock = fill), but it still doesn''t make use of the space. Is there a property akin to the GridList''s FillLastColumn? I''m not looking for that exact same functionality because I''d like have all of the columns be the same size rather than just making the last column fill up the space. But it''s the same sort of idea. I am able to resize the columns to fix the text in them, but I can''t find something to evenly distribute the widths of all columns to fill the whole panel. It seems I could figure the width of the panel, divide by num columns and then set them all to that. But the part that makes it tricky is that the TaskBarBox and panel resize along with the form. So that would be a lot of ugly recalculating every time the form is resized to get the grid right. So before I went down that path I wanted to see if there''s a better way of doing this. Example screenshot: GDBG_screenshot_1834.zip Thanks! Will

2 Replies

AD Administrator Syncfusion Team September 16, 2005 01:59 PM UTC

Hi Will, You could try handling QueryColWidth to see if it helps. private void Model_QueryColWidth(object sender, GridRowColSizeEventArgs e) { if(e.Index > this.gridDataBoundGrid1.Model.Cols.HeaderCount) { //clientsize = ClientSize - Row Headers int clientsize =this.gridDataBoundGrid1.ClientSize.Width - this.gridDataBoundGrid1.Model.ColWidths.GetTotal(0, this.gridDataBoundGrid1.Model.Cols.HeaderCount); e.Size = (int)clientsize / this.gridDataBoundGrid1.Model.ColCount; e.Handled = true; } XPTaBar.zip Best Regards, Jay N


WK Will Knoll September 21, 2005 08:20 AM UTC

Thank you very much for your assistance here Jay, your suggestion works perfectly! Will

Loader.
Live Chat Icon For mobile
Up arrow icon