繁体   English   中英

迭代GridView Rows并单独设置图像

[英]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;

此代码设置列中所有单元格的图像。如何在循环中单独编辑单元格图像?

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

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

如果需要有许多不同的图像,请使用Cells文章的“ 单元 格图标”部分中描述的方法之一。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM