如何在屏幕截图中的2个datagridviews中选择多行? Example 我做了一行:
private void dataDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
Selection();
}
private void Selection()
{
table2DataGridView.ClearSelection();
int selected = Convert.ToInt32(table1DataGridView.CurrentRow.Index);
if (table1DataGridView.Rows.Count != 0)
{
table2DataGridView.Rows[selected].Selected = true;
}
}
但不知道如何处理多行。
答案 0 :(得分:0)
要同步两个DataGridView
的选定行,您可以处理第一个网格的SelectionChanged
事件并以这种方式设置第二个网格的选定行:
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
this.dataGridView2.ClearSelection();
this.dataGridView1.SelectedRows.Cast<DataGridViewRow>().Select(x => x.Index)
.ToList().ForEach(i =>
{
if (i < this.dataGridView2.RowCount)
this.dataGridView2.Rows[i].Selected = true;
});
}