如何根据从数据库返回的值在 Dev express 数据网格中设置图标
问问题
18768 次
1 回答
18
以下是步骤。
- 将 ImageCollection 添加到您的表单/窗口并添加一些 16x16 的图标。
- 为图标添加一列到网格。
- 将列的 fieldName 设置为 image (无论你喜欢什么)。
- 将列的 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。
于 2010-11-29T04:23:01.360 回答