我用下面的代碼找到的DataGridView一行,並突出顯示該行。DataGridView-如何跳轉到搜索中選定的行?
private void btnSearch_Click(object sender, EventArgs e)
{
currentMode = ModeSelection.Search;
if (cmbSearchBy.SelectedIndex == Convert.ToInt16(SearchBy.MaterialID))
{
dgvSearchResults.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
int rowIndex = -1;
try
{
foreach (DataGridViewRow row in dgvSearchResults.Rows)
{
if (row.Cells[1].Value.ToString().Equals(materialLocation.MaterialID))
{
//Select the row here
rowIndex = row.Index;
dgvSearchResults.Rows[rowIndex].Selected = true;
break;
}
}
}
catch (Exception ex) { throw ex; }
}
它完美地工作。問題是我的DataGridView有500多條記錄,如果選定的行靠近DataGridView的底部,用戶必須一直向下滾動到底部。我可以使用哪些代碼跳轉到我正在查找的行?任何幫助將非常感謝!