Resizing the GridControl

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

4 Replies

AD Administrator Syncfusion Team September 17, 2003 08:03 AM UTC

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.


AN Andrew September 17, 2003 05:18 PM UTC

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.


AD Administrator Syncfusion Team September 17, 2003 06:02 PM UTC

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


AN Andrew September 17, 2003 06:16 PM UTC

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

Loader.
Up arrow icon