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?
i have the same problem but only if i load my datasource from xml at runtime, what i have to do in that case?
Are you sure it's the same problem? It seems to me that the original problem here was a problem with the poster's implementation of the data source classes. It seems very unlikely that you are having the same problem or that the cause of the problem is the same. Unless you are writing your own data source class and made exactly the same error.