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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

ResizeToFit in DropDownGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

12934 Apr 15,2004 01:33 PM UTC Apr 19,2004 10:14 AM UTC WinForms 6
loading
Tags: GridControl
Ron Huebner
Asked On April 15, 2004 01:33 PM UTC

I''m having trouble using the ResizeToFit function in the DropDownGrid sample project. I would like the dropdown grid columns to be resized to fit. In the DropDownGrid sample code below I added the last line: '' create a couple of child grids to be placed in two dropdowns GridA = New GridControl() GridA.RowCount = 10 GridA.ColCount = 5 GridA.ThemesEnabled = True GridA.CausesValidation = False GridA(1, 1).Text = "Grid A" GridA.ColWidths.ResizeToFit(GridRangeInfo.Table()) The last line fails with: An unhandled exception of type ''System.NullReferenceException'' occurred in syncfusion.grid.dll Additional information: Object reference not set to an instance of an object. How do I fix this?

Administrator [Syncfusion]
Replied On April 15, 2004 03:25 PM UTC

You have to do this resize call after the grid has been added to its parent. So, you might try calling after you create the CellModel for this dropdown grid. If that still is not late enough, then you can subscribe to the parent grid''s CurrentCellShowingDropDown, and if the current cell is GridA''s cell, then call the resize from your event handler.

Ron Huebner
Replied On April 16, 2004 10:09 AM UTC

Clay, Thanks for the reply. This got me getting closer to a solution. I added the ResizeToFit into the CurrentCellShowingDropDown handler which I was already exploiting to custom size the drop down grid (see code below). On the first click to a dropdown grid I get a NullReferenceException error when I hit the ResizeToFit line. If I handle this error the dropdown grid displays w/o the ResizeToFit. If I click again to cause the dropdown grid to reveal itself everything works fine - the dropdown grid is resized w/o error. Any suggestions on how to work around this? Regards, Ron '''' the dropdown grid sizing handler Private Sub gridControl_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As GridCurrentCellShowingDropDownEventArgs) Dim cc As GridCurrentCell = sender.CurrentCell '' the following will size the grid control area to match the grid size. If cc.Renderer.GetType() Is GetType(DropDownGridCellRenderer) Then Dim grid As GridControl = CType(cc.Renderer.Model, DropDownGridCellModel).EmbeddedGrid grid.HScroll = False grid.VScroll = False grid.HScrollBehavior = GridScrollbarMode.Disabled grid.VScrollBehavior = GridScrollbarMode.Disabled Try grid.ColWidths.ResizeToFit(GridRangeInfo.Table(), GridResizeToFitOptions.IncludeHeaders) Catch ex As System.SystemException MsgBox(ex.ToString) End Try Dim w As Integer = grid.Model.ColWidths.GetTotal(0, grid.Model.ColCount) + 16 Dim h As Integer = grid.Model.RowHeights.GetTotal(0, grid.Model.RowCount) + 16 '' limit the grid size to the 80% of the form size If w > 0.8 * Me.Width Then w = 0.8 * Me.Width grid.HScrollBehavior = GridScrollbarMode.Automatic h = h + 20 End If If h > 0.8 * Me.Height Then h = 0.8 * Me.Height grid.VScrollBehavior = GridScrollbarMode.Automatic w = w + 20 End If e.Size = New Size(w, h) End If End Sub

Administrator [Syncfusion]
Replied On April 16, 2004 10:30 AM UTC

Sort of lost here.... Might try calling grid.Refresh() at the bottom of the handler. This will do a couple of thing including UpdateScrollBars and ResetVolatileData calls. It might be useful to run the code with debug library builds (if you own the source code, you can use the Assembly Manager to create debug builds.). This should allow you to get a detailed callstack at the exception an dto see exactly what is null. Maybe that would point to a solution. If you can post a sample project, we can try it here.

Ron Huebner
Replied On April 16, 2004 01:29 PM UTC

Clay, I have attached the zipped modified VB dropdown grid demo project. Perhaps this will help get to the underlying issue. Thanks, Ron VB_861.zip

Administrator [Syncfusion]
Replied On April 16, 2004 04:24 PM UTC

What version are you using? I can see the problem in 1618, but not in the latest 20 code base. In 1618, I was able to avoid the problem by calling Initialize on the embedded grid. xModel.EmbeddedGrid = GridX GridX.Initialize() ''added.....

Ron Huebner
Replied On April 19, 2004 10:14 AM UTC

I''m using 1618, the Initialize call fixed the problem. Thanks for your assistance.

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.

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

;