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. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridGroupingControl column width dynamically

Thread ID:

Created:

Updated:

Platform:

Replies:

69548 Nov 1,2007 08:29 AM UTC Nov 12,2007 10:48 AM UTC WinForms 4
loading
Tags: GridControl
Christoph Gasser
Asked On November 1, 2007 08:29 AM UTC

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 ;-)

haneefm [Syncfusion]
Replied On 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

Christoph Gasser
Replied On November 1, 2007 03:41 PM UTC

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

Christoph Gasser
Replied On 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


Christoph Gasser
Replied On 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;
}
}
}


CONFIRMATION

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.

Warning Icon 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.Close Icon

;