簡體   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