How do I display an image in a cell?
I have done this previously but its not working in 2009.1 Grid.
I have tried the Image and ImageBackground but neither appear. The image I am setting it to does exist and contain data.
Here is the code:
private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) { try { e.Row.Cells["STOCK_IMAGE"].Appearance.ImageBackground = Image.FromFile("C:\\jon2.jpg"); e.Row.Cells["STOCK_IMAGE"].Appearance.ImageBackgroundStyle = Infragistics.Win.ImageBackgroundStyle.Centered; e.Row.Cells["STOCK_IMAGE"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Image; } catch { } }
I've managed to get it to work now. The Grid's UseAppStyling was preventing it from being displayed. The value is still a string but on the IntializeRow event I am setting the cell appearance imagebackbround to the image I want and all seems ok.
jonathanchannon said:If I set the value it says it cannot convert Bitmap to String. Why does the value need to be set. Isn't this done when the grid binds to the DataTable.
Well, you can't assign an image to the value of a cell in a column whose data type is string.
I assumed this was a column of DataType Image or maybe Bitmap.
If you can't change the data type of the column, then you would have to use a CreationFilter to put an image into the cell rather than just using an Image as the value. You would trap for the creation of the CellUIElement's child elements and replace them with a single ImageUIElement with the image you want.
If I set the value it says it cannot convert Bitmap to String. Why does the value need to be set. Isn't this done when the grid binds to the DataTable.
Are you trying to display an image in the cell along with the text already in the cell? Or do you just want the entire cell to display the image?
The problem with the code you have here is that you are doing half of each.
If you want the image to show up along with the text, just set the Appearance.Image on the cell. Do not set the Style to Image.
If you want the whole cell to simply be an image without any text and without any editing, then you should set the Style of the cell to Image and set the Value of the cell to the image you want. Also... if the whole column is displaying images, it would be more efficient to set the style on the Column, rather than on each individual cell.