我有一个用C#编写的窗口应用程序。我里面有一个datagridview。这是代码:
private List<Tablet> tabletList = new List<Tablet>();
...
private void tabControl1_Selected(object sender, TabControlEventArgs e)
{
GetTabletList();
}
void GetTabletList()
{
Tablet newTablet = new Tablet();
newTablet.xxx = yyy;
newTablet.xxx2 = yyy2;
tabletList.Add(newTablet);
dataGridView.DataSource = tabletList;
Console.WriteLine(tabletList.Count);
}
public class Tablet
{
public string xxx { get; set; }
public string xxx2 { get; set; }
}
每次调用GetTabletList()
时,值tabletList.Count
都会不断增加,但我只能在datagridview中看到1行。怎么了?
答案 0 :(得分:0)
尝试ObservableCollection<Tablet>
代替List<Tablet>