Datagridview 显示当前选中行

///

/// 显示当前选中行 /// private void ShowCurrentRows() { for (int i = 0; i < dgv_list.Rows.Count; i++) { if (dgv_list.Rows[i].Selected == true) { RowsIndex = i; //记录当前选中行 FirstDisplayedScrollingRowIndex = dgv_list.FirstDisplayedScrollingRowIndex; //记录当前选中行所在可视范围首行 break; } } } if (dgv_list.Rows.Count > 0) { try { dgv_list.Rows[RowsIndex].Selected = true; dgv_list.FirstDisplayedScrollingRowIndex = FirstDisplayedScrollingRowIndex; } catch { dgv_list.FirstDisplayedScrollingRowIndex = 0; dgv_list.Rows[0].Selected = true; } }

你可能感兴趣的:(c#)