Fit grid columns to the grid size

Hi,

I want to have a Data Bound grid with a default behaviour that when I attach a table with N number of columns it should use all the size allocated to the grid.

Right now it's so happening that I have a larger grid size defined and columns are not covering all the defined area of the grid and it's looking odd.

I think this behaviour is present in GGC. Could you tell me which properties to set to get this behaviour?

5 Replies

DH Dheeraj November 22, 2006 09:34 AM UTC

Please provide any solution.. Basically I need an AutoFit behaviour: given the size of the grid and columns, the grid should atuomatically fit the columns using all the space provided.

Thanks,
Dheeraj


AD Administrator Syncfusion Team November 22, 2006 10:02 AM UTC

Hi Dheeraj,

Please use this sample code handling TableModel.QueryColWidth and SizeChanged event to see if that meets your requirements:

this.gridGroupingControl1.TableModel.QueryColWidth +=new Syncfusion.Windows.Forms.Grid.GridRowColSizeEventHandler(TableModel_QueryColWidth);
this.gridGroupingControl1.SizeChanged +=new EventHandler(gridGroupingControl1_SizeChanged);

private void TableModel_QueryColWidth(object sender, Syncfusion.Windows.Forms.Grid.GridRowColSizeEventArgs e)
{
int last = this.gridGroupingControl1.TableDescriptor.VisibleColumns.Count;
if(e.Index == (last + this.gridGroupingControl1.TableDescriptor.GroupedColumns.Count))
{
e.Size = (this.gridGroupingControl1.Width - ((this.gridGroupingControl1.TableDescriptor.VisibleColumns.TotalWidth -1)+ (this.gridGroupingControl1.TableDescriptor.GroupedColumns.Count * this.gridGroupingControl1.TableOptions.IndentWidth)));
e.Handled = true;
}
}

private void gridGroupingControl1_SizeChanged(object sender, EventArgs e)
{
this.gridGroupingControl1.TableControl.Refresh();
}

Best Regards,
Haneef


DH Dheeraj November 22, 2006 10:16 AM UTC

Hi Haneef,

Could you provide the code for DataBoundGrid. I don't see this snippet will compile for DataBoundGrid.

Thanks,
Dheeraj


AD Administrator Syncfusion Team November 22, 2006 10:32 AM UTC

Hi Dheeraj,

Here is a KB on percentage sizing the columns in a GridDataBoundGrid.
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=304

Best Regards,
Haneef


DH Dheeraj November 23, 2006 06:04 AM UTC

We are using this code with some modification. Thank you!

Loader.
Up arrow icon