dataGridView图像不显示第一行,第二个单元格 [英] dataGridView Image not displaying for first row, second Cell

查看:411
本文介绍了dataGridView图像不显示第一行,第二个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我有一个dataGridView,我试图显示一个图像(使用DataGridViewImageColumn),所有相应的行都有图像,除了第一行(这也是我可以看到的唯一一行视觉工作室的编辑)下面的图像是我得到的,我希望他们都是绿色的复选标记。如何实现?





请注意,我已经尝试过以下操作:
在启动时更改或删除我的选择;
使用不同的图像;动态设置图像(代码);和一些随机更改的设置。任何帮助将高度赞赏!我很感谢大家的帮助,请让我知道,如果我可以提供更多的信息。

解决方案

 code>命名空间WindowsFormsApplication1 
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender,EventArgs e)
{
列表< MyItem> items = new List< MyItem>(); (int i = 0; i< 10; i ++)
{
items.Add(new MyItem {Key = i,value = Image.FromFile(@e:\ test.jpg)});
}

this.dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.Columns.Clear();
this.dataGridView1.Columns.Add(Key,Key);
this.dataGridView1.Columns.Add(new DataGridViewImageColumn(){HeaderText =Status});

this.dataGridView1.Columns [0] .DataPropertyName =Key;
this.dataGridView1.Columns [1] .DataPropertyName =value;

this.dataGridView1.DataSource = items;

}
}

public class MyItem
{
public int Key {get;组; }
public Image value {get;组; }
}

}


Okay so I have a dataGridView that I am trying to display an image on (using the DataGridViewImageColumn), all of the appropriate rows have the image, except for row one (this is also the only row that I can see in the visual studio's editor) The image below is what I am getting, I want all of them to be the green check mark though. How might I accomplish that?

Please note that I have already tried the following: Changing or removing my selection on start-up; Using a different image; Setting the image dynamically (in code); and a bit of randomly changing settings. Any help would be highly appreciated! I thank you all in advance for the help, please let me know if I can supply anymore information.

解决方案

   namespace WindowsFormsApplication1   
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        List<MyItem> items = new List<MyItem>();
        for (int i = 0; i < 10; i++)
        {
            items.Add(new MyItem { Key = i, value = Image.FromFile(@"e:\test.jpg") });
        }

        this.dataGridView1.AutoGenerateColumns = false;
        this.dataGridView1.Columns.Clear();
        this.dataGridView1.Columns.Add("Key", "Key");
        this.dataGridView1.Columns.Add(new DataGridViewImageColumn() { HeaderText="Status"});

        this.dataGridView1.Columns[0].DataPropertyName = "Key";            
        this.dataGridView1.Columns[1].DataPropertyName = "value";

        this.dataGridView1.DataSource = items;

    }
}

public class MyItem
{
    public int Key { get; set; }
    public Image value { get; set; }
}

}

这篇关于dataGridView图像不显示第一行,第二个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆