Iterating through GridView Rows and setting image individually

644 views Asked by At

I have a Devexpress DataGridView.A column named TEST is set to display an image using RepositoryItemTextEdit

 RepositoryItemTextEdit te = new RepositoryItemTextEdit();
 _grd.RepositoryItems.Add(te);
 _rgv.Columns["TEST"].ColumnEdit = te;
 te.ContextImage = myimage;

This code sets the image for all cells in the column.How can i individually edit the cell images in a loop?

2

There are 2 answers

2
Lex EPoX On BEST ANSWER

If you have a limited number of images, I would recommend creating a few repository items and assign them to cells conditionally in the GridView.CustomRowCellEdit event.

If you need to have a number of different images, use one of the approaches described in the Cell Icons section of the Cells article.

2
Marko Juvančič On

Handle CustomDrawCell event.

private void _grd_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) {
  if (e.Column.FieldName == "TEST") {
    var te = (e.Cell as GridCellInfo).ViewInfo as TextEditViewInfo;
    te.ContextImage = GetCustomImageForThisRow(); // <-- your custom logic 
  }
}