【问题标题】:Image in Windows Forms DataGridViewWindows 窗体 DataGridView 中的图像
【发布时间】:2023-04-03 16:16:01
【问题描述】:

我有一个带有 DataGridView 的表单。 DataGridView 的来源是 BindingList 这是 Tiger 类:

  public class Tiger
{
    public string Name { get; set; }
    public int Weight { get; set; }
    public DateTime Born { get; set; }
    public String Picture { get; set; }

    public Tiger(string name, int weight, DateTime born)
    {
        Name = name;
        Weight = weight;
        Born = born;
        Picture = "D:\\Dropbox\\Uni\\NET\\tigers";
    }
}

我希望“图片”列在“图片”字段中显示带有 URI 的图像,而不是字符串。如何实现?

【问题讨论】:

  • 对该列使用 ItemTemplate;添加Image标签并将source属性绑定到实际图片路径

标签: c# datagridview


【解决方案1】:

为此,请在您的 datagridview 中创建一个列类型 Image 并在您的 Tiger 类中创建一个 byte[] 属性。

在您的构造函数中,您将图像读取为byte[] 并设置属性。

在 datagridview 的 Image 列中使用 byte[] 属性

【讨论】:

    【解决方案2】:

    也许这段代码可以帮助你:

            FileStream fs = new System.IO.FileStream(@"Images\a.bmp", FileMode.Open, FileAccess.Read); 
    pictureBox1.Image = Image.FromStream(fs);
    
      fs.Close();
    

    显示此link

    祝你好运

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-12
      • 1970-01-01
      • 2016-05-23
      • 1970-01-01
      • 1970-01-01
      • 2011-03-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多