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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

dropdown grid not setting size properly

Thread ID:





6551 Aug 16,2003 02:47 PM UTC Aug 16,2003 06:32 PM UTC WinForms 1
Tags: GridControl
Asked On August 16, 2003 02:47 PM UTC

I have a dropdown grid (called gridDBSub) that during the _Resize event, sets the column widths to utilize the full clientwidth. Works fine, EXCEPT the first time the sub grid is dropped, the ClientRectangle.Width returns the width of the control as it sits on the IDE, but not as it displays. If, however, I close the dropdown and then re-show, the ClientRectangle.Width correctly returns the width of the control as being displayed. Specifically: ClientRectangle.Width = 40 the first time its displayed(although its physically showing much wider), and returns 340 from there on out. (Also, gridDBSub.Width = 42 and 342 thereafter). How can I get the sub-grid to return the actualy width of the control, as it's drawn, the first time the _Resize method is called? I tried calling _Resize manually in the VisibleChanged event, but that had no effect. I've also tried .Refresh, again, no effect. Thanks Eric

Administrator [Syncfusion]
Replied On August 16, 2003 06:32 PM UTC

You can set this last column size in the CurrentCellShowingDropDown event. There is a 8 pixel border on each side of the dropdown window that explains the 16 pixel fudge factor in the code below. Also, on the very first drop, the grid has not been initialize fully yet, so the code gets things like row count and column count from the DataSource (which the code assumes is a DataTable). GridA is the embedded grid in the drop window.
private bool bFirstTime = true;
private void gridControl1_CurrentCellShowingDropDown(object sender, GridCurrentCellShowingDropDownEventArgs e)
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if(bFirstTime && this.gridControl1[cc.RowIndex, cc.ColIndex].CellType == "GridADropCell")
		bFirstTime = false;
		GridA.AllowResizeToFit = false;
		DataTable dt = GridA.DataSource as DataTable;
		if(dt != null)
			int cols = dt.Columns.Count;
			int sbWidth = SystemInformation.VerticalScrollBarWidth;
			int rows = (GridA.EnableAddNew) ? dt.Rows.Count + 1 : dt.Rows.Count; 
			if(rows * GridA.DefaultRowHeight + GridA.Model.RowHeights[0] + 16 
				< e.Size.Height)
				sbWidth = 0;
				GridA.VScrollBehavior = GridScrollbarMode.Disabled;
			int width = e.Size.Width - GridA.Model.ColWidths.GetTotal(0, cols-1) - sbWidth - 16;
			GridA.Model.ColWidths[cols] = width;


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon