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"
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?
ADAdministrator Syncfusion Team April 15, 2004 10:25 AM
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.
RHRon HuebnerApril 16, 2004 05:09 AM
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?
'''' 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
Catch ex As System.SystemException
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
If h > 0.8 * Me.Height Then
h = 0.8 * Me.Height
grid.VScrollBehavior = GridScrollbarMode.Automatic
w = w + 20
e.Size = New Size(w, h)
ADAdministrator Syncfusion Team April 16, 2004 05:30 AM
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.
RHRon HuebnerApril 16, 2004 08:29 AM
I have attached the zipped modified VB dropdown grid demo project. Perhaps this will help get to the underlying issue.
ADAdministrator Syncfusion Team April 16, 2004 11:24 AM
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
RHRon HuebnerApril 19, 2004 05:14 AM
I''m using 1618, the Initialize call fixed the problem. Thanks for your assistance.