c# - 如何在 devexpress 数据网格中包含图像

标签 c# devexpress xtragrid

如何根据从数据库返回的值在 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/

相关文章:

winforms - 如何更改 BarButtonItem 的背景颜色?

c# - NETSDK1073 : The FrameworkReference 'Microsoft.AspNetCore.App' was not recognized

c# - Entity Framework 查询outofmemoryexception

c# - PATH 变量的 GetEnvironmentVariable() 和 SetEnvironmentVariable()

c# - 读取xml节点属性

c# - 如何在 XtraGridControl Devexpress 上设置焦点行?

c# - DevExpress GridControl BestFit |自动调整模式?

c# - SQL依赖使用存储过程

asp.net - ASPxGridView - 如何获取主从 GridView 的详细信息网格中的选定行?

c# - 当 ChildRow 没有数据时,从 XtraGrid GridView 的 MasterRow 中删除向下钻取加号图标 (+)