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.
Unfortunately, activation email could not send to your email. Please try again.

Update ImageIndex of GridControl Cell

Thread ID:

Created:

Updated:

Platform:

Replies:

95429 Jul 7,2010 04:17 PM Jul 8,2010 07:39 AM Windows Forms 1
loading
Tags: GridControl
Nathaniel Felt
Asked On July 7, 2010 04:17 PM

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.

Christopher Issac Sunder K [Syncfusion]
Replied On July 8, 2010 07:39 AM

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()
{
InitializeComponent();
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.

http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=GC_ImageIndex-1700992398.zip

Please let me know if you have any other concerns.

Regards,
Christo

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;