遍历 GridView 行并单独设置图像

Iterating through GridView Rows and setting image individually

我有一个名为 TEST 的 Devexpress DataGridView.A 列设置为使用 RepositoryItemTextEdit

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

此代码为 column.How 中的所有单元格设置图像我可以单独编辑循环中的单元格图像吗?

如果您的图像数量有限,我建议您创建一些存储库项目并在 GridView.CustomRowCellEdit 事件中有条件地将它们分配给单元格。

如果您需要许多不同的图像,请使用 Cell Icons section of the Cells 文章中描述的方法之一。

处理 CustomDrawCell 事件。

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 
  }
}