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.
Unfortunately, activation email could not send to your email. Please try again.

Autosizing grid columns to fit available space

Thread ID:





34801 Sep 16,2005 04:09 AM Sep 21,2005 04:20 AM Windows Forms 2
Tags: GridControl
Will Knoll
Asked On September 16, 2005 04:09 AM

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

Administrator [Syncfusion]
Replied On September 16, 2005 09:59 AM

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

Will Knoll
Replied On September 21, 2005 04:20 AM

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


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.