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

Resizing the GridControl

Thread ID:

Created:

Updated:

Platform:

Replies:

7242 Sep 16,2003 09:52 PM Sep 17,2003 02:16 PM Windows Forms 4
loading
Tags: GridControl
Andrew
Asked On September 16, 2003 09:52 PM

Hello, I created a GridControl object that has 9 columns. I want to manually set the size for 8 of the 9 cells. However, I would like one of the cells to resize itself proportional to the client area of the form. I used the code below to test out the resizing function. I experienced redrawing issues when maximizing the form. The grid resizes itself when the form dimensions are changed, but the redrawing of the cells is not accurate. I have to double click each of the column headings to get the column widths to appear correctly. What is the best way to accomplish my goal (stated above)? #Region "Form Level Variables" Private proportionalGridCell As Boolean = True #End Region #Region "Form Load" Private Sub Form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AddHandler grdWorkSheet.Model.QueryColWidth, AddressOf GetColWidth End Sub #End Region #Region "Resize Columns Function" 'Resize Columns to fill the entire Grid control. Private Sub GetColWidth(ByVal sender As Object, ByVal e As GridRowColSizeEventArgs) If Me.proportionalGridCell And e.Index > 0 Then e.Size = CInt(Math.Ceiling(CDbl(Me.grdWorkSheet.ClientRectangle.Width - grdWorkSheet.Model.ColWidths(0)) / grdWorkSheet.Model.ColCount) - 1) e.Handled = True End If End Sub #End Region Thanks, Andrew

Administrator [Syncfusion]
Replied On September 17, 2003 04:03 AM

I think if you set the grid.SmoothControlResize = false in your form.load, it will avoid the drawing problem you are seeing. Using the QueryColWidth is a good way to implement this type of functionality.

Andrew
Replied On September 17, 2003 01:18 PM

Setting grid.SmoothControlResize = false in the form load event worked perfectly. However, I still haven't figured out how to get only one field to resize as the grid is resized. I have 9 columns and I want 8 of them to resize to the colum headers text. For this I used the following code: 'Resize columns. grdWorkSheet.ColWidths.ResizeToFit(GridRangeInfo.Cells(0, 1, 0, 3), GridResizeToFitOptions.IncludeHeaders) grdWorkSheet.ColWidths.ResizeToFit(GridRangeInfo.Cells(0, 5, 0, 9), GridResizeToFitOptions.IncludeHeaders) Notice that I left column 4 out of the ResizeToFit method calls. This is the column I want to resize (bigger) when the form is resized. In summary, I want the grid to always fill the maximum space in the form, and I want column 4 to expand as the form expands. This is what I tried: #Region "Resize 'Description' Column Function" Private Sub GetColWidth(ByVal sender As Object, ByVal e As GridRowColSizeEventArgs) If Me.proportionalGridCell And e.Index > 0 Then Dim totalColsWidth As Integer = grdWorkSheet.ColWidths.GetTotal(1, 9) grdWorkSheet.ColWidths(4) = CInt((Me.grdWorkSheet.ClientRectangle.Width) - (totalColsWidth) - (grdWorkSheet.GetColWidth(4))) End If End Sub #End Region Unfortunately, this did not work. I got the following error: "An unhandled exception of type 'System.StackOverflowException' occurred in syncfusion.grid.dll" Can you please help me with this, Andrew > I think if you set the grid.SmoothControlResize = false in your form.load, it will avoid the drawing problem you are seeing. > > Using the QueryColWidth is a good way to implement this type of functionality.

Administrator [Syncfusion]
Replied On September 17, 2003 02:02 PM

Try
Private Sub GetColWidth(ByVal sender As Object, ByVal e As GridRowColSizeEventArgs)
	If Me.proportionalGridCell And e.Index  = 4 Then
  		dim left as Integer = grdWorkSheet.ColWidths.GetTotal(0, 3)
		dim right as Integer = grdWorkSheet.ColWidths.GetTotal(5, 9)
		e.Size  = CInt((Me.grdWorkSheet.ClientRectangle.Width) - right - left)
		e.Handled = True
	End If
End Sub

Andrew
Replied On September 17, 2003 02:16 PM

Thanks, this is exactly what I was looking for. I totally missed the e.index = 4. Thanks again, Andrew > Try >
> Private Sub GetColWidth(ByVal sender As Object, ByVal e As GridRowColSizeEventArgs)
> 	If Me.proportionalGridCell And e.Index  = 4 Then
>   		dim left as Integer = grdWorkSheet.ColWidths.GetTotal(0, 3)
> 		dim right as Integer = grdWorkSheet.ColWidths.GetTotal(5, 9)
> 		e.Size  = CInt((Me.grdWorkSheet.ClientRectangle.Width) - right - left)
> 		e.Handled = True
> 	End If
> End Sub
> 
>

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.

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.

;