Hello,
I'm trying to show an image on an cell. I've created a new column and changed the DataType. and in the InitializeRow i'm saying which photo should appear, but this don´t work. The column appears empty. Here´s my code:
InitializeLayout... gData.DisplayLayout.Bands[0].Columns.Add("New"); UltraGridColumn col = gData.DisplayLayout.Bands[0].Columns["New"]; col.DataType = typeof(Bitmap); col.Header.Caption = CM.GetString("New"); col.Header.VisiblePosition = 1;...
InitializeRow... if ((bool)e.Row.Cells["ReadByAssignedTo"].Value) img2 = new Bitmap(Properties.Resources.newTask); else
img2 = new Bitmap(Properties.Resources.oldTask);
e.Row.Cells["New"].Value = img2; //e.Row.Cells["New"].Appearance.ImageBackground = img2;...
Can you please tell me what's wrong with this code?
Thanks
Just to clear up a little confusion here... there are two different ways to put an image in a cell.
If you just want a cell to display an image from the data and nothing else, then the way you have here in the original post is correct. You set the data type of the column to Bitmap and then assign an image to the Value of the cell. If that's not working, then my only guess is that you are using a really old version of the grid that doesn't automatically detect Bitmap and display it as an image. If that's the case, all you have to do is set the Style on the column to Image.
the other way, using an Appearance, will only work for cells of other types. It will not work for a picture-style cell, because the image on the Appearance is intended to display along with the other data in the cell, not by itself. And it doesn't make any sense to have a cell whose value is an image and then to display an additional image in that cell along with the image from the cell's value.
Hello ,
Please find the attached sample which is based on your requierments.
Test it out at your end and let me know what are the results that you are getting.
That´s what i have too. But it don´t show any image. If i put this image in any other column as ImageBackground it works, but in this new column it don't appears. And how about the code to create the new column on the InitializeLayout that i posted? Is that correct?
I have tried the following code in the InitializeRow event of the UltraGrid and it work as expected.
if ((bool)e.Row.Cells["New"].Value) { img2 = Image.FromFile("First.jpg"); } else { img2 = Image.FromFile("Second.jpg"); }
//You are able to use this one to set the Background Imagee.Row.Cells["Image"].Appearance.ImageBackground = img2;
//Or you the following one to show your desired image as a value
e.Row.Cells["Image"].Value = img2;
So if your column is empty are you hooking you InitializeRow event to the UltraGrid?
Please try this at your end and let me know if you have any further questions.
Sincerely,
Danko Valkov
Developer Support Engineer
Infragistics, Inc.