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

GridGroupingControl column width dynamically

Hi,

I have a GGC and want the column width change dynamically. For my GridDataBoundGrids I've doe this using the information / code from this posting: http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=70

That works perfectly fine for the GDBG but not for my GGC. For this I found a posting: http://www.syncfusion.com/support/Forums/message.aspx?MessageID=61835

So I tried to create a (helper) class that does the same then the GDBG class. My problem is, that the available space is changing based on the level of grouping. In the given example there is a fixed number of level (child, grandchild). Is it possible to check if there is a child for each level and rund through the complete table model (like building up a tree view)?

like:

if(there is a deeper grouping level)
{
assign col width for table model;
levelnumber++;
}

BR
Christoph

PS: If you have already a class which does what I need, that would be also fine - even better ;-)

4 Replies

HA haneefm Syncfusion Team November 1, 2007 03:03 PM UTC

Hi Christoph,

To provide column widths dynamically, you need to handle the TableModel.QueryColWidth event. In your handler, you set the width of any column. The below sample shows how you can have the right-most or left-most column grow to fill the grid's client area as the grid size changes.

Here is a minimal sample will allow you to use a helper class to manage this functionality. The helper class supports the left or right column fill the client area. You can customize the helper class depends on your requirement.
http://websamples.syncfusion.com/samples/Grid.Windows/F67383/main.htm

Please refer this KB article which explains "How to allocate equal size for each of the columns in all the tables of a GridGroupingControl?"
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=356

Best Regards,
Haneef


CG Christoph Gasser November 1, 2007 03:41 PM UTC

Thank you Haneef! That's exactly what I was looking for. Briliant support!!!


CG Christoph Gasser November 12, 2007 10:00 AM UTC

I've implemented your code and have one more little question: Is it possible to get the grouping level of the current table? The example you've given in http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=356 is fine if you know how much levels of grouping you have. Is it possible to change the code from http://websamples.syncfusion.com/samples/Grid.Windows/F67383/main.htm so that it is working when the grid is grouped?

BR
Christoph



CG Christoph Gasser November 12, 2007 10:48 AM UTC

SOLVED. Here's my code:


void TableModel_QueryColWidth(object sender, GridRowColSizeEventArgs e)
{
GridTableModel gridModel = sender as GridTableModel;
GridTableControl gridtc = (GridTableControl)gridModel.ActiveGridView;

if (gridModel != null && grid != null)
{
int availableArea;
int VSBarSize = 0;
if (_vScrollVisible)
VSBarSize = SystemInformation.VerticalScrollBarWidth;

_indentCols = (gridModel.GetColumnIndentCount()) * gridtc.GroupingControl.TableOptions.IndentWidth;

switch (_colSizeBehavior)
{
case GridColSizeBehavior.FillRightColumn:
if (e.Index == (this.grid.TableDescriptor.VisibleColumns.Count + gridModel.GetColumnIndentCount() - 1) && e.Index > gridModel.Cols.HeaderCount + gridModel.GetColumnIndentCount() - 1)
{
availableArea = gridtc.GroupingControl.ClientSize.Width - _indentCols - VSBarSize;
e.Size = availableArea - this.grid.TableModel.ColWidths.GetTotal(0, this.grid.TableDescriptor.VisibleColumns.Count - 1);
e.Handled = true;
}
break;
case GridColSizeBehavior.FillLeftColumn:
if (e.Index == ((gridModel.Cols.FrozenCount + 1) + (gridModel.GetColumnIndentCount() - 1)))
{
availableArea = gridtc.GroupingControl.ClientSize.Width - _indentCols - VSBarSize;
int leftPiece = gridModel.ColWidths.GetTotal(0, gridModel.Cols.FrozenCount);
int rightPiece = gridModel.ColWidths.GetTotal(gridModel.Cols.FrozenCount + 2, gridModel.ColCount);
e.Size = availableArea - leftPiece - rightPiece;
e.Handled = true;
}
break;

default:
break;
}
}
}


Loader.
Live Chat Icon For mobile
Up arrow icon