我有一个用 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 行。怎么了?