I have an UltraGrid that list a bunch of services my company offers. One of the fields is an Icon.
The database will keep a column of Type Image for this Icon. The Datasource of the Grid is a .Net BindingSource The Bindingsource is set to a bindable BusinessObject
The best way that I've found to add an Image to the database is to do it in the application. However when I load up the grid, which is set to a Bindable Business Object The value for this Image Field is Null (Naturally, as I've not been able to add it to the database yet) So I set the InitializeRow Event to detect if the paticular Icon Cell is Null if it is I want to Display a button and if it's not I want to display the Icon.
So far everything works.
Now when the image is null I press the button in the application I get an OpenFile Dialog box and I select the image that I want to load in the database. I then parse the data as I should and Set the style of the cell to Image, I then set the Value of the Cell to the byte[ array of the Image. when this happens I get a NullReferenceException on cell.value
I'm confused because of course it's null right now I want to set it and it keeps coming up with the exception. Anybody have any idea's on how to fix it?
{
//Convert Sender to UltraGrid Object
OpenFileDialog ofLoadIcon = new OpenFileDialog();
Bitmap icon = new Bitmap(ofLoadIcon.FileName);
icon.Save(mstr, icon.RawFormat);
e.Cell.Value = file;
e.Cell.Appearance.ImageBackground = icon;
e.Cell.Column.MinWidth = icon.Width;
}
Exactly what line of code is throwing the exception. What does the call stack show?
The Exact line is
e.cell.value = file;
Here is the stacktrace
System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object." Source="System" StackTrace: at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value) at Infragistics.Win.UltraWinGrid.UltraGridRow.SetCellValue(UltraGridColumn column, Object val, Boolean suppressErrorMessagePrompt, Boolean throwExceptionOnError) at Infragistics.Win.UltraWinGrid.UltraGridCell.SetValueInternal(Object value, Boolean suppressErrorMessagePrompt, Boolean fireInitializeRow, Boolean throwExceptionOnError) at Infragistics.Win.UltraWinGrid.UltraGridCell.SetValueInternal(Object value, Boolean suppressErrorMessagePrompt, Boolean fireInitializeRow) at Infragistics.Win.UltraWinGrid.UltraGridCell.set_Value(Object value) at ProposalSystem.Form1.ugAdminServices_ClickCellButton(Object sender, CellEventArgs e) in C:\C2Development\PSDynamicServices\ProposalSystem\ProposalSystem\Form1.cs:line 981 at Infragistics.Win.UltraWinGrid.UltraGrid.OnClickCellButton(CellEventArgs e) at Infragistics.Win.UltraWinGrid.UltraGrid.FireEvent(GridEventIds id, EventArgs e) at Infragistics.Win.UltraWinGrid.UltraGridCell.OnButtonClick() at Infragistics.Win.UltraWinGrid.ButtonWithStyleUIElement.OnClick() at Infragistics.Win.ControlUIElementBase.ProcessMouseUpHelper(Object sender, MouseEventArgs e) at Infragistics.Win.ControlUIElementBase.ProcessMouseUp(Object sender, MouseEventArgs e) at Infragistics.Win.Utilities.ProcessEvent(Control control, ProcessEvent eventToProcess, EventArgs e) at Infragistics.Win.UltraControlBase.OnMouseUp(MouseEventArgs e) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
According to this, the data source is blowing up in the PropertyDescriptor SetValue. What's your data source?
Hi Mike ,
I have the exact same error message as above. I get this error when I click on New Row and Immediately after that if i click on any other row it throws this exceptio.
so this happens only when i try to add a new row and without andding any data into it I change the focus to some other row.
please help
Without a lot more information, it's impossible for me to guess why you are getting an error.
What do you mean by "exactly the same error message?" You mean the entire call stack is the same? Or do you mean you are getting a NullReferenceException?
A NullReferenceException just means that something in the code is trying to reference a property on a null object, which can be caused by any number of coding errors.
If you are, in fact, getting exactly the same error message, then the solution to this is the same as it was for the previous 2 reports.
Mike,
I could atleast figure out where the problem is.
The problem is with the formulas. if the grid has even one column with the formula. this error is thrown.when i removed all the formula in the columns the error goes away.
I tried putting formulas back one ata time but no change same error pops up.
how can i hadle this in my code ? which event do i capture.?