C# 将datagridview绑定到列表<;字典<;字符串,字符串>&燃气轮机;

C# 将datagridview绑定到列表<;字典<;字符串,字符串>&燃气轮机;,c#,dictionary,datagridview,bind,C#,Dictionary,Datagridview,Bind,如何将datagridview绑定到字典列表? 例如: 字典本身就是列表(阅读集合)。但字典并不是一个正确的绑定集合。它还有其他用途 不管你怎么做 public class Foo { public int Ean { get; set; } public string Titre { get; set; } public int Prix { get; set; } public int Quantite { get; set; } } Lis

如何将datagridview绑定到字典列表? 例如:

字典本身就是列表(阅读集合)。但字典并不是一个正确的绑定集合。它还有其他用途

不管你怎么做

public class Foo
{        
    public int Ean { get; set; }
    public string Titre { get; set; }
    public int Prix { get; set; }
    public int Quantite { get; set; }
}

List<Foo> lst = new List<Foo>();

Foo f = new  Foo();
f.Ean = Convert.ToInt32(txtStockEAN.Text);
f.Titre = txtStockTitre.Text;
f.Prix = Convert.ToInt32(txtStockPrix.Text);
f.Quantite = Convert.ToInt32(txtStockQuantite.Text);
lst.Add(f);
公共类Foo
{        
公共整数Ean{get;set;}
公共字符串标题{get;set;}
公共int Prix{get;set;}
公共整数量化{get;set;}
}
List lst=新列表();
Foo f=新的Foo();
f、 Ean=Convert.ToInt32(txtStockEAN.Text);
f、 Titre=txtStockTitre.Text;
f、 Prix=Convert.ToInt32(txtStockPrix.Text);
f、 Quantite=Convert.ToInt32(txtStockQuantite.Text);
第1条添加(f);

在我的WinForm中,我添加了一个按钮,其功能是:
private void btnPanierAjouter_Click(object sender,EventArgs e){//your code(不含foo类)dataGridView1.DataSource=lst;}
当我第一次单击它时,结果被添加到dataGridView1,但当我再次单击它时,没有任何更改,为什么?我添加了这段代码及其okey`BindingSource bs=newbindingsource();bs.DataSource=lst;dataGridView1.DataSource=bs;`思考
ean    |     titre     |    prix    |     quantite     
__________________________________________________
1      |     titre1    |    10      |     100          
2      |     titre2    |    20      |     200          
...       
public class Foo
{        
    public int Ean { get; set; }
    public string Titre { get; set; }
    public int Prix { get; set; }
    public int Quantite { get; set; }
}

List<Foo> lst = new List<Foo>();

Foo f = new  Foo();
f.Ean = Convert.ToInt32(txtStockEAN.Text);
f.Titre = txtStockTitre.Text;
f.Prix = Convert.ToInt32(txtStockPrix.Text);
f.Quantite = Convert.ToInt32(txtStockQuantite.Text);
lst.Add(f);