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

Docking problems with Grid control?

I'm having bazarre docking problems with the grid control. The grid's scroller controls dock fine with the Parent panel control; however, the grid separates from its scrollers as the window enlarges. Things look fine if I reduce the width or height of my form though. I have a form that includes a user control that contains left and right panels in Explorer style with a treeview on the left and the grid on the right and a splitter in the middle. The Treeview is happy when the form changes size but the grid looks strange. thanks, Rollan

4 Replies

CB Clay Burch Syncfusion Team August 24, 2002 08:43 AM UTC

Rollan, I am not sure I understand exactly what you are describing. Is it that the number of columns and rows are insufficient to fill the clientarea that is enlarged as the window is sized because the grid's DockStyle is set to Fill? If so, then this behavior is as expected since the grid's scrollbars are at the edge of the grid's clientarea. It is just the grid does not have enough rows/columns to occupy the entire clientarea. There would be a couple of ways of avoiding this look. One might be to only dock the grid to the left and top, and not use Fill. In this case, you would also want to set the grid's clientarea to the size of the area that would have been filled. Another way might be to dynamically size the right-most column so it fills any empty clientspace. The GridListControl has a property that sets this behavior. You implement it by handling the QueryColWidth event, and if the request is for the last column, provide the exact width that would fill any empty clientarea. You can see the exact code in the QueryColWidth handler of the GridListControl class. If this does not explain what you are seeing, can you provide more details?

RM Rollan Mosko August 24, 2002 06:29 PM UTC

Hi Clay, Thanks for the reply- working on a Saturday- I'm impressed! What I'm trying to do is grow the rightmost column so it stretches as the control widens. I have just 2 columns in my sample grid. I tried your suggestion of handling the QueryColWidth() event. What I do is get the GridSize and then calculate what the right column should be by subtracting the 1st column from the size of the grid. I'm not sure how to accomplish the column size query for the first column though. I was looking at the supplied samples and noticed the virtual treegrid sample. I was thinking it might be beneficial for me and others if the necessary logic was added to that sample to show how we can expand the D column appropriately to always fill the right part of the grid. That mimics what I'm trying to do quite well.

CB Clay Burch Syncfusion Team August 24, 2002 09:08 PM UTC

Rollan, Below is the code to expand the right column in the VirtTreeGrid sample. In implementing this expandable right column in this particular sample, there is a refresh problem as you size the grid larger. You can add a SizedChanged handler, and redraw the last column to handle this refresh problem. -Clay (still working on Sat...)
void GridQueryColWidth(object sender, GridRowColSizeEventArgs e) 
	if( e.Index == 1)
		e.Size = 200;
	else if(e.Index == gridControl1.ColCount)//fill grid with last col
		int width = gridControl1.ColWidths.GetTotal(0, gridControl1.ColCount-1);
		e.Size = Math.Max(20, gridControl1.ClientRectangle.Width-width);
	else if (e.Index > 0)
		e.Size = 100;
		e.Size = 0;//hide the header // 30;
	e.Handled = true;

private void gridControl1_SizeChanged(object sender, System.EventArgs e)

RM Rollan Mosko August 26, 2002 01:35 PM UTC

Hi Clay, Thanks a bunch. Your code fixes the problem pretty well. I needed to also factor in the DockPadding used in the grid's parent window (a panel) to reduce a little gap between the vertical scroller and the right column. For some reason I needed to factor 4x the doc padding instead of 2x like I would have expected. Don't know why that's needed, but 4x works. thanks, Rollan

Live Chat Icon For mobile
Up arrow icon