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

GridListControl.FillLastColumn equivalent for GridControl?

Is there an equivalent method/property for GridListControl.FillLastColumn in the GridControl? I have tried to implement this with the Resize events but there''s a corner case where the last column disappears and no events get triggered.

13 Replies

AD Administrator Syncfusion Team July 18, 2006 10:15 AM UTC

Hi Palmer, You can handle the QueryColWidth event, and if the requested column (e.Index) is the last column, then set e.Size equal to the needed width to fill the clientwidth. You can see some sample code in the thread. http://www.syncfusion.com/forums/message.asp?MessageID=2699 Also refer the following form threads for more details. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=41072 http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=34801 Let me know if this helps. Best Regards, Haneef


AD Administrator Syncfusion Team July 18, 2006 10:28 AM UTC

Hi Haneef, I''m getting a StackOverFlowException. Unless I''m doing something horribly wrong, I''d assume this is a bug? Here''s the code I wrote in the eventhandler void grid_QueryColWidth(object sender, GridRowColSizeEventArgs e) { e.Handled = e.Index == grid.ViewLayout.LastVisibleRow; if (e.Handled) e.Size = grid.ViewLayout.RectangleRightOfCol (e.Index, GridCellSizeKind.ActualSize).Width; } If I set a breakpoint on the e.Index == ... line, then the breakpoint gets hit and then after a few seconds the process quits.


AD Administrator Syncfusion Team July 18, 2006 11:13 AM UTC

Hi Palmer, Try this code snippet to resolve this issue. Please find the code snippet below. bool fillLastColumn = false; protected virtual void GridQueryColWidth(object sender, GridRowColSizeEventArgs e) { if (this.fillLastColumn && e.Index == Grid.ColCount) { int width = Grid.ColCount <= 0 ? 0 : Grid.ColWidths.GetTotal(0, Grid.ColCount-1); e.Size = Grid.ClientRectangle.Width-width; e.Handled = true; } } Here is a sample. http://www.syncfusion.com/Support/user/uploads/GridControlBorder_c05efd1c.zip Also refer this Knowledge base article which demonstrates the way to resize the columns in a grid. KB : GridPercentageSizing If I did not answer your question, please explain a little more about what you want, and I’ll try again. Best Regards, Haneef


AD Administrator Syncfusion Team July 18, 2006 11:42 AM UTC

Hi Haneef, Your sample works, but it doesn''t take into account hidden columns, but was easily taken care of. It didn''t explain the problem with the StackOverFlowException though. I assume the ViewLayout methods aren''t supposed to be called during resize events? Is there any way to find out what methods are safe to call during what eventhandlers?


AD Administrator Syncfusion Team July 18, 2006 12:14 PM UTC

As I was cleaning up my code a bit I tried to move the calculation of the hidden column width into the eventhandler and lo and behold, again a StackOverFlowException. So I guess there''s no way to obtain any sort of width information (apart from GetTotal) from the grid while in the QueryColWidth event handler?


AD Administrator Syncfusion Team July 18, 2006 01:37 PM UTC

Haneef, Actually, the solution provided here (http://www.syncfusion.com/Support/user/uploads/GridControlResize_edcaba52.zip) (from the off by 1 thread) exhibits the same problem I had with my own solution. If you perform these steps, the last column disappears! 1. grab the splitter between the ''B'' and ''C'' column and drag it completely to the right and release. Note that a very small ''C'' column remains. 2. Now hover over the right hand side of the ''C'' column until you get the resize icon <-|->. Click the left mouse button and release. Note that the ''C'' column disappears completely and doesn''t return when resizing the ''B'' or ''A'' column. Also note that no events get triggered when executing step 2.


AD Administrator Syncfusion Team July 19, 2006 12:26 PM UTC

Hi Palmer,

Issue 1: StackOverflow Exception.

The reason for StackOverflow exception is that the grid.ColWidth[col] indexer calls the GetWidth method. GetWidth method raises the all QuerySize event. You can use the GetTotal method to resolve this exception. By default hidden column width is zero in a grid.

Issue 2: Disapper the "C" Column

You can handle the ResizingColumns event and set e.Cancel = true for required column "C". You can see the code snippet below.

if( e.Columns.Left == 3 )
{
e.Cancel = true;
}

Thanks,
Haneef


AD Administrator Syncfusion Team July 19, 2006 12:56 PM UTC

Hi Haneef,

1. The ResizingColumns event worked out ok, thanks.

2. GetTotal does include the width of the rowheaders column, even if it''s hidden, you''re right about the other columns. bug?



AD Administrator Syncfusion Team July 19, 2006 01:28 PM UTC

Hi Palmer,

Thanks for your update.

GetTotal method is used to get the total size for the specified range of columns( including the hidden column and RowHeader column ) in a grid. By default Hidden column size is zero. So no need to calculate the width of the Hidden column.

To calculate the width of all the column except header column size, you need to use the below code snippet.

this.gridControl1.ColWidths.GetTotal(this.gridControl1.Cols.HeaderCount , gridControl1.ColCount-1 )

You can find the width of the RowHeader column using below code snippet.

this.gridControl1.ColWidths.GetTotal(0,0);

Thanks,
Haneef


AD Administrator Syncfusion Team July 19, 2006 01:49 PM UTC

Haneef,

Sure, I understand all that.

I was just wondering why GetTotal (0,x) includes the width of the rowheader column *when it''s hidden* and at the same time doesn''t include the width of other hidden columns.

I guess I don''t see the reason for this inconsistency.



AD Administrator Syncfusion Team July 20, 2006 01:43 PM UTC

Hi,

We are currently looking into this issue and will update you the details.

Thanks for your patience.
Best Regards,
Haneef


AD Administrator Syncfusion Team July 24, 2006 09:37 AM UTC

Hi,

The GetTotal method checks for the hidden rows/cols in the GridModelHideRowColIndexer and skips those rows/cols. Setting the Properties.RowHeaders to false will not set the RowHeader column as hidden in the GridModelHideRowColIndexer and thus the GetTotal method will not skip the RowHeader column while calcualting the total colwidth. To resolve this, you can set the RowHeader column as hidden in the GridModelHideRowColIndexer.

this.gridControl1.Cols.Hidden[0] = true;

Let me know if this helps.
Best Regards,
Haneef


AD Administrator Syncfusion Team July 25, 2006 09:04 AM UTC

Hi Haneef,

That clears things up, I get the correct width now after setting the rowheader column explicitly to hidden.

Thanks

Loader.
Live Chat Icon For mobile
Up arrow icon