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

ResizeToFit in DropDownGrid

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?

6 Replies

AD Administrator Syncfusion Team 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.

RH Ron Huebner 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

AD Administrator Syncfusion Team 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.

RH Ron Huebner 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

AD Administrator Syncfusion Team 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.....

RH Ron Huebner April 19, 2004 10:14 AM UTC

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

Live Chat Icon For mobile
Up arrow icon