I'm getting rather frustrated trying to display an image in a cell.
First, I'm adding an extra column maually to contain the image cell, like this:
Infragistics.Win.UltraWinGrid.UltraGridColumn iconColumn= grid.DisplayLayout.Bands[0].Columns.Add("IconColumn"); grid.DisplayLayout.Bands[0].Columns["IconColumn"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Image;grid.DisplayLayout.Bands[0].Columns["IconColumn"].Hidden = false;grid.DisplayLayout.Bands[0].Columns["IconColumn"].Header.VisiblePosition = 0;grid.DisplayLayout.Bands[0].Columns["IconColumn"].Header.Caption = "Icon";
Next, in the InitializeRow event, I say:
if (Convert.ToBoolean(e.Row.Cells["RadioExists"].Value.ToString())== true) { e.Row.Cells["IconColumn"].Appearance.BackColor = System.Drawing.Color.Black; e.Row.Cells["IconColumn"].Appearance.Image = System.Drawing.Image.FromFile(@"FilePath");
}
it colors the cell fine, but doesn't show my image. I'm sure the image exists and it is loaded because I've checked the Appearance.Image after it runs and there is a value in there. What am I doing wrong?
I always set the value of the column to a System.Drawing.Image .. i don't think its the appearance that you're looking for.
e.Row.Cells["Key"].Value = image
also, I'm not sure how much IO overhead there is in doing Image.FromFile for every row but you might consider pre-loading your images in the form's Load or something and just making the assignment when the rowInit fires.
I've actually got an ImageList which contains all the images I need, but I changed it in the code example to try and simplify it.
I changed the line to be:
e.Row.Cells["IconColumn"].Value = imageList.Images["Icon"];
Now I get an error reading "Object must implement IConvertible". Any thoughts?
You may have a couple issues. First supply the data type of your column as well.
I.E.
UltraGridColumn isReservedImageColumn = band.Columns.Insert(index, DataTableNames.NominationsView_IsReserveNomImage);
isReservedImageColumn.DataType = typeof(System.Drawing.Bitmap);
then you might need to confirm the type of image you have in your image list, also, it may need to be cast as the correct type.
Here is another post which losely describes other alternatives : http://forums.infragistics.com/forums/p/4311/20881.aspx#20881
That last one did it. I added the line to set the column DataType and it worked fine after that.
Thanks for your help.
PS - I had the Appearances stuff setup already, but wasn't using it yet because I wanted to see it work coming straight from an image first. Now that it's working, I can shift over to he Appearances.