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;
}
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.?
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
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.
i have the same problem but only if i load my datasource from xml at runtime, what i have to do in that case?