We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Update ImageIndex of GridControl Cell

I have a grid control with several rows of data. When I insert these rows into the grid control I give the set the CellType of the first data column to GridCellTypeName.Image and set its ImageList and ImageIndex values.

The problem I am running into is is I can't seem to update the ImageIndex to a different value when new conditions are met. Is it possible to change to the image?

Any help is appreciated.

1 Reply

Christopher Issac Sunder K July 8, 2010 11:39 AM UTC

Hi Nathaniel,

Thank you for your interest in Syncfusion products.

You can update the image index of a cell which contains their cell type as “Image” through “PrepareViewStyleInfo” event, when new conditions are met. In the given sample, the image will change when the first column value is changed.

public Form1()
this.gridControl1.ColStyles[2].CellType = "Image";
this.gridControl1.ColStyles[2].ImageList = this.imageList1;
this.gridControl1.ColStyles[2].ImageSizeMode = Syncfusion.Windows.Forms.Grid.GridImageSizeMode.StretchImage;
this.gridControl1.ColStyles[1].CellValueType = typeof(int);
this.gridControl1.DefaultRowHeight = 64;
this.gridControl1.RowCount = this.imageList1.Images.Count;
for (int i = 0; i < this.gridControl1.RowCount; i++)
this.gridControl1[i + 1, 1].CellValue = i;
this.gridControl1.PrepareViewStyleInfo += new Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventHandler(gridControl1_PrepareViewStyleInfo);
int[] index = new int[20];
void gridControl1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e)
if (e.ColIndex == 1)
if (e.Style.CellValue.ToString() != string.Empty && int.Parse(e.Style.CellValue.ToString()) < this.imageList1.Images.Count)
index[e.RowIndex] = int.Parse(e.Style.CellValue.ToString()); // save the changes
this.gridControl1.RefreshRange(GridRangeInfo.Cell(e.RowIndex, 2)); // refresh the adjacent cell to raise the event once again.
if (e.ColIndex == 2 && e.Style.CellType == "Image")
e.Style.ImageIndex = index[e.RowIndex]; // set the image index.

Please refer the sample in the below link.


Please let me know if you have any other concerns.

Live Chat Icon For mobile
Up arrow icon