2013-05-07 133 views
0

好吧,所以我有一個dataGridView,我試圖顯示圖像(使用DataGridViewImageColumn),所有適當的行都有圖像,除了第一行(這是也是我可以在視覺工作室的編輯器中看到的唯一一行)下面的圖片就是我所得到的,我希望所有這些都是綠色的複選標記。我該怎麼做到這一點?dataGridView圖像不顯示第一行,第二個單元格

enter image description here

請注意,我已經試過如下: 更改或在啓動時刪除我的選擇; 使用不同的圖像;動態設置圖像(在代碼中);和一些隨機更改設置。任何幫助將不勝感激!我提前感謝您的幫助,請讓我知道我是否可以提供任何信息。

+0

您可以張貼在這裏電網的完整圖像? – Eugene 2013-05-07 01:11:02

回答

2
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; } 
} 

} enter image description here

+0

非常感謝Eugene,我現在已經掌握了所有的工作,祝你的項目順利,再次感謝你! – 2013-05-07 03:28:09

相關問題