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.
Unfortunately, activation email could not send to your email. Please try again.

GridGroupingControl and "Object reference not set"

Thread ID:





20455 Oct 19,2004 07:56 AM Nov 4,2004 07:52 AM Windows Forms 11
Tags: GridControl
Olivier Mayo
Asked On October 19, 2004 07:56 AM

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?

Administrator [Syncfusion]
Replied On October 19, 2004 11:41 AM

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.

Administrator [Syncfusion]
Replied On October 19, 2004 11:50 AM

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

Olivier Mayo
Replied On October 21, 2004 08:48 AM

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

Olivier Mayo
Replied On October 21, 2004 12:10 PM

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

Administrator [Syncfusion]
Replied On October 21, 2004 12:26 PM

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

Olivier Mayo
Replied On October 21, 2004 01:26 PM

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

Olivier Mayo
Replied On October 26, 2004 06:30 AM

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

Administrator [Syncfusion]
Replied On October 26, 2004 07:23 AM

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

Olivier Mayo
Replied On October 29, 2004 12:16 PM

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

Administrator [Syncfusion]
Replied On October 29, 2004 12:52 PM

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

Replied On November 4, 2004 07:52 AM

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


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.

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.