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
close icon

GDBG Version 2.1.0.9 - Getting new errors

I wouldn''t normally post here & open a Direct-Trac issue but this error is now stopping me from making a delivery. I have a derived class based on GridStaticCellModel where I have created a custom dropdown to fill in the values of the field. In the OnButtonClicked event, I retrieve a string value from the form and do the following (to cover my bases) : this.Grid.Model[rowIndex, colIndex].Text = strColumnText; this.Grid.CurrentCell.Renderer.ControlText = strColumnText; this.Grid.CurrentCell.Renderer.ControlValue = strColumnText; If I add a this.NotifyCurrentCellChanged() statement, I get the error at the bottom of this message all the time. If I remove it, I get it the second time that I make a change to this cell. What''s going on? This used to work!! P.S. - I don''t have any code in ConfirmChanges so it''s an internal error. catched at Syncfusion.Windows.Forms.Grid.GridCurrentCell.ConfirmChanges(Boolean closeDropDown) in :line 0 catched at Syncfusion.Windows.Forms.Grid.GridCurrentCell.Deactivate(Boolean discardChanges) in :line 0 An unhandled exception of type ''System.NullReferenceException'' occurred in syncfusion.grid.dll Additional information: Object reference not set to an instance of an object. Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.

10 Replies

AD Administrator Syncfusion Team August 27, 2004 07:11 PM UTC

I do not know what is causing this problem. Here is the code from the baseclass call.
protected virtual void NotifyCurrentCellChanged()
{
	TraceUtil.TraceCurrentMethodInfoIf(Switches.CellRenderer.TraceVerbose);
	CurrentCell.NotifyChanged();
}
Is CurrentCell null? If you own the source code for our libraries, you can use the Assembly Manager (found on the Syncfusion Start menu) to build a debug version of the libraries. Then if you set the debugger to break on exceptions, you should be able to step into the code to see eexactly what is null, and hopefully track down what needs to be done to avoid it. If you can post a sample project showing the problem, we can try to do this debug work here.


LS Lori S. Pearsall August 27, 2004 07:25 PM UTC

I don''t own the source code version. I''ve added debug code to the CurrentCellValidating event and OnSaveChanges since the documentation states that those two routines are invoked from ConfirmChanges. The following values are NOT null : CurrentCell, CurrentCell.Renderer.ControlText, CurrentCell.Renderer.ControlValue, Model[row,col].Text, Model[row,col].CellValue What other values is ConfirmChanges looking for?


AD Administrator Syncfusion Team August 27, 2004 08:00 PM UTC

You say you are deriving GridStaticCellModel and GridStaticCellRenderer. Have you explicitly renderer.Control to a control you have created for your renderer class? If so, then you normally save the value to the grid by overriding renderer.OnSaveChanges. There you would set grid.model[RowIndex, ColIndex] to the control value. When you set the control value like in your renderer.OnButtonClicked handler, you would set only the control value, not the grid value. When you set the control value, you would set grid.CurrentCell.IsModified = true. When you do this, it tells teh grid to call your OnSaveChanges method (which save teh value to the grid) as the cell renderer loses focus.


LS Lori S. Pearsall August 27, 2004 08:12 PM UTC

That gives me the same results. However, I have now noticed that this seems to be happening just on new records in the grid. I''ve done a Binder.BeginEdit prior to making changes - what else can I do so that ConfirmChanges doesn''t error out?


LS Lori S. Pearsall August 27, 2004 10:56 PM UTC

It seems that any of my derived controls (overriding a CellRenderer) in my grid now exhibit a problem working with the "AppendRow". Some of these controls are from samples downloaded from the forum so it''s hard to say whether this is a new problem or not - although I must have gotten new values into the grid at some point in time. Anyway, following the basic model of : OnButtonClicked contains : if (this.NotifyCurrentCellChanging()) { ControlValue = xx; this.NotifyCurrentCellChanged(); } OnSaveChanges contains : if (HasControlValue) { this.Grid.Model[row,col].CellValue = xx; this.Grid.CurrentCell.IsModified = false; } How do I avoid these NullReferenceExceptions that are being generated in SaveCellInfo/ConfirmChanges? I''ve tried the following code in CurrentCellValidating : if (!grid.Binder.IsEditing) grid.Binder.BeginEdit(); "Code to put a primary key in the record" grid.Binder.EndEdit(); but it doesn''t avoid the problem.


LS Lori S. Pearsall August 27, 2004 11:33 PM UTC

Here''s a sample that I had downloaded from the forum. I''m getting these errors in my grid from typing directly into the cells or returning values from a dropdown form. At least this sample exhibits the same NullReferenceException error that I''m getting in SaveCellInfo/ConfirmChanges, so hopefully the same fix will apply. Instructions : Go to the grid on the right and scroll down to the append row. Type some text into Col1 (the shaded one) and then tab out. RichTextInPlaceCellContol_7936_1299.zip


AD Administrator Syncfusion Team August 28, 2004 01:08 AM UTC

In the sample, you can avoid the problem by adding a grid.CurrentCellStartEditing handler in the form as below. We will look at resolving this issue in our library, but until we do maybe adding this handler will also work around it for you too.
private void gridDataBoundGrid1_CurrentCellStartEditing(object sender, CancelEventArgs e)
{
	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
	if(cc.RowIndex == this.gridDataBoundGrid1.Model.RowCount)
	{
		this.gridDataBoundGrid1.Binder.AddNew();
	}
}


LS Lori S. Pearsall August 28, 2004 02:44 AM UTC

You''re right - this does work in the sample. Unfortunately, it doesn''t help in my application - ALL instances of derived controls give NullReferenceExceptions in ConfirmChanges when on the "AppendRow" regardless of whether the control has the value typed into the cell or brought back from a dropdown form. Does the fact that I''m binding to a DataTable make a difference? I put WriteLine''s in the CurrentCellStartEditing code that you suggested to confirm that the AddNew was occurring and I also confirmed that the Binder.RecordCount had been incremented. Visually, a new record is added to the grid. But, same error. I am at such a loss and I have a delivery due Monday. This HAD to have worked at some point in time just due to the fact that I have data in my database.


AD Administrator Syncfusion Team August 28, 2004 09:05 AM UTC

Here is what I think is the real problem in the sample. The changed event is not triggerring the notification event required to let the grid know that a change is being made. That left the grid state not set to be in the AddNew mode which is triggerring the problem. Adding the notification call makes things work without relying on the CurrentCellStartEditing event to force the grid in the proper state. So, in your case remove the CurrentCellStartEditing work-around that did not work, and in your renderer''s change event (or however you are noting your control has changed), make sure you call NotifyCurrentCellChanging. Here is teh code that fixes the sample.
//used to set cell changes flag
private void activeRichTextBox_TextChanged(object sender, EventArgs e)
{
	if (!this.NotifyCurrentCellChanging())
				this.Grid.CurrentCell.IsModified = true;
}


LS Lori S. Pearsall August 29, 2004 01:00 AM UTC

Hi Clay, Thanks so much!! Lori

Loader.
Live Chat Icon For mobile
Up arrow icon