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

GridGroupingControl and "Object reference not set"

I use, in my application, a grid grouping control. I bind data to it using the "DataSource" property. I trap the "QueryCellStyleInfo" event to change cell color and set if the cells are editable or not (using "enabled" and "readOnly" properties). So, basicilly, I bind data from the database to it, the user modifies the required cells and the application then updates the database consequently. It used to work fine when I was only binding the data to it (without the "editing" portion done), but it now has a weird behavior. The only significant thing I changed is that I now handle the "TableControlCurrentCellEditingComplete" event, which recalculates my row totals and sets the cell values using ggc.TableModel(iRow, iCol).CellValue = dNewValue Here is what happends : If I click on any editable cell and it gets the focus (with the ''I'' cursor) and hit TAB, it shows a message box that says "Object reference not set to an instance of an object". I checked and that error is not fired in the "TableControlCurrentCellEditingComplete" event (it occurs after, and not in my code). It looks like if the grid itself shows that message. However, if I modify the content of ONE cell and THEN hit TAB, everything is fine for all editable cells. Got any clues?

11 Replies

AD Administrator Syncfusion Team October 19, 2004 03:41 PM UTC

Can you set teh debugger to stop on exception, an dthen post the callstack? I suspect the problem is that setting ggc.TableModel(iRow, iCol).CellValue = dNewValue at this point may be triggerring teh exception. I fyou comment out this line, does the problem go away? If so, you can try few things like setting the value directly in your DataSource and not in the grid. Or, you set a flag in this event to indicate that you need to do your calculations, and then check this flag in TableControlCurrentCellMoved to see if setting teh value there works better.


AD Administrator Syncfusion Team October 19, 2004 03:50 PM UTC

Hi Olivier, try also handling the SourceListListChanged event. This event is called when the grid receives a IBindingList.ListChanged event. By default if the current record is modified from the outside the current cell gets deactivated. My suspicion is that this is your problem (and a subsequent call in the CurrentCell code after you event returns then suddenly has no current cell anymore and has null ref problem). When you handle that event you can instruct the grid not to deavtivate the current record by setting e.ShouldResetCurrentRecord = false; Stefan


OM Olivier Mayo October 21, 2004 12:48 PM UTC

You were right... The line ggc.TableModel(iRow, iCol).CellValue = dNewValue is the one that throws the exception. I''ll try your suggestions and will keep you informed ;)


OM Olivier Mayo October 21, 2004 04:10 PM UTC

Thanks a lot Clay ;) It worked fine!!! You''re a genius!!! There''s only one other problem I just can''t solve... When I press TAB in a cell, I want the summary row to fresh automatically. The only way it does it is if I press ENTER and then press TAB. Is there any way to force the "commitment" of the cell content so that the summary row refreshes properly? Thank you again ;)


AD Administrator Syncfusion Team October 21, 2004 04:26 PM UTC

You can try calling: groupingGrid.Table.TableDirty = true; groupingGrid.Table.SummariesDirty = true; before setting the value to see if this makes things to refresh.


OM Olivier Mayo October 21, 2004 05:26 PM UTC

WOW! You''re my new God Clay!!! :)


OM Olivier Mayo October 26, 2004 10:30 AM UTC

I still get a problem with "Object reference not set" in my grouping grid control :( I modified my code so that I affect the data source instead of setting the value of the cells manually. I can now navigate through the cells without problems using the mouse and TAB key, but I get the same error as before ("Object reference not set") if I use the left/right keys. Did I forget something??? Here''s my code : ''When we''re done editing the cell Private Sub ggcFacturation_TableControlCurrentCellEditingComplete(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlEventArgs) Handles ggcFacturation.TableControlCurrentCellEditingComplete If e.TableControl.CurrentCell.ColIndex = Me.COL_FACTURATION_AVANCEMENT_NUM Then CalculateFieldsFacturation(e.TableControl.CurrentCell.RowIndex) End If End Sub ''Calculte fields in function of the record data at row iRow Private Sub CalculateFieldsFacturation(ByVal iRow As Int32) Dim dPrixVente As Decimal Dim dAvancement As Decimal Dim dNouveauCumul As Decimal Dim dAFacturer As Decimal dPrixVente = ggcFacturation.TableModel(iRow, COL_FACTURATION_PRIX_VENTE_NUM).CellValue dAvancement = ggcFacturation.TableModel(iRow, COL_FACTURATION_AVANCEMENT_NUM).CellValue dNouveauCumul = dAvancement / 100.0 * dPrixVente dAFacturer = dNouveauCumul - ggcFacturation.TableModel.Item(iRow, COL_FACTURATION_DEJA_FACTURE_NUM).CellValue ''Force the summary row refresh ggcFacturation.Table.TableDirty = True ggcFacturation.Table.SummariesDirty = True ''Modify cell data ggcFacturation.TableControl.Table.BeginEdit() ggcFacturation.TableControl.Table.CurrentRecord.SetValue(COL_FACTURATION_NOUVEAU_CUMULATIF, dNouveauCumul.ToString) ggcFacturation.TableControl.Table.CurrentRecord.SetValue(COL_FACTURATION_A_FACTURER, dAFacturer.ToString) ggcFacturation.TableControl.Table.EndEdit() ggcFacturation.TableControl.Refresh() End Sub


AD Administrator Syncfusion Team October 26, 2004 11:23 AM UTC

Did you try Stefan''s suggestion above, handling SourceListListChanged and setting e.ShouldResetCurrentCell = false?


OM Olivier Mayo October 29, 2004 04:16 PM UTC

I''ld love to, but this property does not exist when I trap the event in my grid grouping control


AD Administrator Syncfusion Team October 29, 2004 04:52 PM UTC

Are you using 2.1.0.9, the latest release? You can get it from your direct trac home page.


PA Pat November 4, 2004 12:52 PM UTC

No, but I found the solution to my problem... My problem never occured when I was modifying the row I am currently editing. However, I wanted to update rows I am not editing in function of the cell I just modified. Here''s what I did... * Note that ROW_COUNT is a constant that stores the number of rows for each record. Basically, in my case, my grid will have 18 rows for 2 records (6 rows for the header, and then 6 rows for each record). So here''s the code : ''Calculate the RECORD row based on the GRID row Dim iRecordRow As Int32 = Math.Ceiling(iRow / ROW_COUNT) - 2 ''Begin editing the record I wish to modify ggcBudget.TableControl.Table.Records(iRecordRow).BeginEdit() ''Modify the cell value ggcBudget.TableModel.Item(iGridRow, iGridCol).CellValue = myNewValue ''We''re done editing ggcBudget.TableControl.Table.Records(iRecordRow).EndEdit()

Loader.
Live Chat Icon For mobile
Up arrow icon