我有2个GridView,当我选择行时,我想将记录从DataGridView1抛出到DataGridView2。
代码如下:
当我点击按钮时,它不会播放所有项目。
stuList.Add(new Student() { id=1,Name = "Jacob", Age = 29, City = "London" });
stuList.Add(new Student() { id=2,Name = "Zulia", Age = 31, City = "London" });
stuList.Add(new Student() { id=3,Name = "Brandon", Age = 35, City = "London" });
defaultDGV.DataSource = stuList;
foreach (DataGridViewRow row in defaultDGV.Rows)
{
if (row.Cells[0].Value != null)
{
string str = row.Cells[1].Value.ToString();
var record = stuList.FirstOrDefault(a => a.Name.Equals(str));
newList.Add(record);
stuList.Remove(record);
}
}
newDGV.DataSource = defaultDGV.DataSource = null;
newDGV.DataSource = stuList;
defaultDGV.DataSource = newList;
我发现var record = stuList.FirstOrDefault (a => a.Name.Equals (str));
正在做一些我不知道的事情。