【问题标题】:Iterating through GridView Rows and setting image individually遍历 GridView 行并单独设置图像
【发布时间】:2019-04-18 06:34:07
【问题描述】:

我有一个 Devexpress DataGridView。名为 TEST 的列设置为使用 RepositoryItemTextEdit 显示图像

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

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

【问题讨论】:

  • 比循环更好的是没有行初始化或列初始化事件,您可以在单个单元格级别设置它

标签: c# .net winforms devexpress xtraeditors


【解决方案1】:

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

【讨论】:

  • 谢谢...如果我使用这种方法..我可以得到存储在那里的原始字符串值吗?
  • 我的意思是在我用 Image(TextEditor) 替换它之后?
【解决方案2】:

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

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

【讨论】:

  • 谢谢.. 有没有办法拥有两个单独的视图,即:每个单元格中的原始字符串数据,然后是另一个视图,即:根据原始视图中的数据呈现数据的渲染视图。
  • 当然。您可以向GridControl.ViewCollection 添加一个视图,然后通过MainView 切换它们
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-02
  • 1970-01-01
  • 2017-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多