try { ncol=dataGridView1.CurrentCell.ColumnIndex; strKey += e.KeyChar.ToString(); foreach (DataGridViewRow row in dataGridView1.Rows) { if (row.Cells[ncol].Value.ToString().ToUpper().Equals(strKey.ToUpper()) || row.Cells[ncol].Value.ToString().ToUpper().Contains(strKey.ToUpper())) { rowIndex = row.Index; colindex = row.Cells[ncol].ColumnIndex; break; } } if (rowIndex != -1) { if (rowIndex >= 5) { if (dataGridView1.FirstDisplayedScrollingRowIndex + dataGridView1.DisplayedRowCount(false) <= rowIndex) { dataGridView1.FirstDisplayedScrollingRowIndex = rowIndex - dataGridView1.DisplayedRowCount(false) + 1; } else if (dataGridView1.FirstDisplayedScrollingRowIndex + dataGridView1.DisplayedRowCount(false) >= rowIndex) { dataGridView1.FirstDisplayedScrollingRowIndex = rowIndex - dataGridView1.DisplayedRowCount(false) + 1; } } else { dataGridView1.FirstDisplayedScrollingRowIndex = rowIndex; } if (dataGridView1.SelectedRows.Count == 0) { dataGridView1.Rows[rowIndex].Selected = true; if (dataGridView1.Rows[rowIndex].Selected == true) { textBox1.Text = dataGridView1.SelectedCells[0].Value.ToString(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)