How can set icon in Dev express data grid depending on the value returning from Database
Asked
Active
Viewed 1.9k times
4
-
Any suggestion how to do this with a Dev Express WinForms TreeList? The call to e.RowHandle fails. Thank you. – user3673052 Feb 16 '21 at 03:32
1 Answers
18
Here are the steps.
- Add an ImageCollection to your form/window and add some icons 16x16 to it.
- Add a column to the Grid for the icons.
- Set the column's fieldName to image (whatever you like).
- Set the column's UnboundType to Object.
- Add a repositoryItemPictureEdit to the column's columnEdit.
All the above can be done in the designer. Then do the following
private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
if (e.Column == colImage1 && e.IsGetData) {
string someValueFromDatabase = (string)gridView1.GetRowCellValue(e.RowHandle, colOne);
if (someValueFromDatabase == "a") {
//Set an icon with index 0
e.Value = imageCollection1.Images[0];
} else {
//Set an icon with index 1
e.Value = imageCollection1.Images[1];
}
}
}
The key here is handling the CustomUnboundColumnData and the repositoryItemPictureEdit.

Osama Rizwan
- 615
- 1
- 7
- 19

Saif Khan
- 18,402
- 29
- 102
- 147
-
2This explanation was so much more straightforward than what I found on the DevExpress site--thanks. DevExpress could use some writers like you. – RobC Nov 07 '12 at 17:41
-
1I think that `imageCollection1.Images(0)` is `imageCollection1.Images[0]` – Askolein Mar 20 '14 at 16:22
-