Datagridview列显示System.Drawing.Bitmap?

那个部分

我有一个Datagridview数据库中的数据填充。

我的数据库表上有3列:id, name, status.但是这些都是文本/字符串格式的。

根据我从数据库的“状态”列(“联机”或“脱机”)获得的数据,我尝试将图像放置在单元上,而不仅仅是普通的“联机”或“脱机”字符串。

我很喜欢DGV这次DataBindingComplete活动。当前具有以下代码:

void DataGridView1DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
    {
        foreach (DataGridViewRow r in dataGridView1.Rows)
        {   
            if (r.Cells["status"].Value.ToString() == "Online")
            {
                // add online image here
                r.Cells["status"].Value = Resource1.MyOnlineIcon;
            }
            else if(r.Cells["status"].Value.ToString() == "Offline")
            {
                // add offline image here
                r.Cells["status"].Value = Resource1.MyOfflineIcon;
            }

        }

但是问题在于它显示System.Drawing.Bitmap在单元格上,而不是实际显示图片。由于在我的数据库中,状态列的数据类型是字符串,因此DGV也将列设置为字符串类型。如何将现有的字符串/文本类型列更改为图像列?解决此问题的最佳方法是什么?

oop

如果您将数据库查询转换为这样的对象集合

public class SomeObject {
    public int ID {get;set;}
    public string Name {get;set;}
    public Bitmap Image {get;set;

    public SomeObject(int id, string name, string status) {
        ID = id;
        Name = name;
        Image = status == "Online" ? Resource1.MyOnlineIcon : Resource1.MyOfflineIcon;
    }

}

通过将其绑定到,它应该可以正常工作DataGridView

List<SomeObject> source = dbConnection.GetObjects();
dataGridView.DataSource = source;

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

DataGridView图像仅显示“ System.Drawing.Bitmap”

来自分类Dev

将System :: Drawing :: Bitmap ^转换为:: MAT

来自分类Dev

System :: Drawing :: Bitmap到cv :: Mat(OpenCV c ++ / cli)

来自分类Dev

将[System.Drawing.Bitmap]转换为[File.IFileAbstraction]

来自分类Dev

在System.Drawing.Bitmap中转换画布的背景?

来自分类Dev

System.Drawing.Image和System.Drawing.Bitmap有什么区别?

来自分类Dev

System.Drawing.Image和System.Drawing.Bitmap有什么区别?

来自分类Dev

无法解析System.Drawing.Bitmap和System.Drawing.ImageConverter

来自分类Dev

将System.Drawing.Bitmap转换为WPF的System.Windows.Media.BitmapImage

来自分类Dev

如何创建从System.Drawing.Bitmap对象开始的iTextSharp.text.Image对象?

来自分类Dev

How can i extract the image out of 'System.Drawing.Bitmap' to file via windbg?

来自分类Dev

如何从“ System.Drawing.Bitmap”中提取图像通过Windbg归档?

来自分类Dev

将类型'System.Drawing.Bitmap'转换为'Emgu.CV.IImage'

来自分类Dev

iOS萤幕撷取画面为Background App中的System.Drawing.Bitmap(Xamarin)

来自分类Dev

SystemAccessViolation将Drawing.Bitmap转换为Emgu.CV.Image

来自分类Dev

新样式 csproj 自动显示对 System.Drawing、FileSystem 等的引用

来自分类Dev

如何使用System.Drawing.Color?

来自分类Dev

Xamarin Android System.Drawing.Image替代

来自分类Dev

在System.Drawing中找不到“点”

来自分类Dev

替换System.Drawing.Point的GetHashCode()方法

来自分类Dev

vNext缺少System.Drawing.Color

来自分类Dev

VS代码如何添加System.Drawing

来自分类Dev

System.Drawing.GDIPlus.CheckStatus System.Drawing.Image.FromFile System.ArgumentException [GDI +状态:InvalidParameter]

来自分类Dev

遍历System.Drawing.Color结构并使用它创建System.Drawing.Pen

来自分类Dev

使用 System.Drawing.Imaging; System.Drawing 中不存在成像

来自分类Dev

无法从程序集“System.Drawing, Version=4.0.0.0”的加载类型“System.Drawing.Font”加载类型

来自分类Dev

为什么无法删除 System.Drawing 并替换为 NuGet 包 System.Drawing.Common

来自分类Dev

System.Drawing.Drawing2D中的Matrix.Multiply的工作原理...不同吗?

来自分类Dev

System.Drawing.Drawing2D Matrix的实现或文档不正确吗?

Related 相关文章

  1. 1

    DataGridView图像仅显示“ System.Drawing.Bitmap”

  2. 2

    将System :: Drawing :: Bitmap ^转换为:: MAT

  3. 3

    System :: Drawing :: Bitmap到cv :: Mat(OpenCV c ++ / cli)

  4. 4

    将[System.Drawing.Bitmap]转换为[File.IFileAbstraction]

  5. 5

    在System.Drawing.Bitmap中转换画布的背景?

  6. 6

    System.Drawing.Image和System.Drawing.Bitmap有什么区别?

  7. 7

    System.Drawing.Image和System.Drawing.Bitmap有什么区别?

  8. 8

    无法解析System.Drawing.Bitmap和System.Drawing.ImageConverter

  9. 9

    将System.Drawing.Bitmap转换为WPF的System.Windows.Media.BitmapImage

  10. 10

    如何创建从System.Drawing.Bitmap对象开始的iTextSharp.text.Image对象?

  11. 11

    How can i extract the image out of 'System.Drawing.Bitmap' to file via windbg?

  12. 12

    如何从“ System.Drawing.Bitmap”中提取图像通过Windbg归档?

  13. 13

    将类型'System.Drawing.Bitmap'转换为'Emgu.CV.IImage'

  14. 14

    iOS萤幕撷取画面为Background App中的System.Drawing.Bitmap(Xamarin)

  15. 15

    SystemAccessViolation将Drawing.Bitmap转换为Emgu.CV.Image

  16. 16

    新样式 csproj 自动显示对 System.Drawing、FileSystem 等的引用

  17. 17

    如何使用System.Drawing.Color?

  18. 18

    Xamarin Android System.Drawing.Image替代

  19. 19

    在System.Drawing中找不到“点”

  20. 20

    替换System.Drawing.Point的GetHashCode()方法

  21. 21

    vNext缺少System.Drawing.Color

  22. 22

    VS代码如何添加System.Drawing

  23. 23

    System.Drawing.GDIPlus.CheckStatus System.Drawing.Image.FromFile System.ArgumentException [GDI +状态:InvalidParameter]

  24. 24

    遍历System.Drawing.Color结构并使用它创建System.Drawing.Pen

  25. 25

    使用 System.Drawing.Imaging; System.Drawing 中不存在成像

  26. 26

    无法从程序集“System.Drawing, Version=4.0.0.0”的加载类型“System.Drawing.Font”加载类型

  27. 27

    为什么无法删除 System.Drawing 并替换为 NuGet 包 System.Drawing.Common

  28. 28

    System.Drawing.Drawing2D中的Matrix.Multiply的工作原理...不同吗?

  29. 29

    System.Drawing.Drawing2D Matrix的实现或文档不正确吗?

热门标签

归档