如何根据从数据库返回的值在 Dev Express 数据网格中设置图标
最佳答案
这是步骤。
- 将 ImageCollection 添加到您的表单/窗口并向其添加一些 16x16 图标。
- 在网格中为图标添加一列。
- 将列的字段名称设置为图像(无论 你喜欢)。
- 将列的 UnboundType 设置为 Object。
- 添加一个 repositoryItemPictureEdit 到 该列的 columnEdit。
以上都可以在设计器中完成。然后执行以下操作
private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
if (e.Column == colImage1 && e.IsGetData) {
string someValueFromDatabase = (string)gridView1.GetRowCellValue(e.RowHandle, colOne);
if (someValueFromDatabase == "a") {
//Set an icon with index 0
e.Value = imageCollection1.Images[0];
} else {
//Set an icon with index 1
e.Value = imageCollection1.Images[1];
}
}
}
这里的关键是处理 CustomUnboundColumnData和 repositoryItemPictureEdit。
关于c# - 如何在 devexpress 数据网格中包含图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4291409/