'검색'버튼을 클릭하지 않고 DGV를 통해 검색을 시작할 수있는 기능을 찾고 있습니다.C#, WinForms - 'ENTER'버튼으로 검색 프로세스 시작
private int SearchValueRowIndex()
{
string searchValue = textBox1.Text;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.Value != null && cell.Value.ToString() == searchValue)
{
return cell.RowIndex;
}
}
}
// Not found
return -1;
}
SearchValueRowIndex :
private int SearchValueRowIndex()
{
string searchValue = textBox1.Text;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.Value != null && cell.Value.ToString() == searchValue)
{
return cell.RowIndex;
}
}
}
이 지금은 필요없이 SearchButton의 활성화를위한 새로운 클래스를 열려고은 클릭 그 때문에 나는 클릭에 검색 프로세스를 시작하는 검색 버튼을 만든 그것에 :
private void button1_KeyPress(object sender, KeyEventArgs e)
{
if (e.KeyValue.ToString() == Keys.Enter.ToString())
{
button1.PerformClick();
}
}
하지만 작동하지 않습니다. 이미 몇 가지 변경 사항을 시도했지만 제대로 작동하지 않았습니다. 오류나 예외가 나타나지 않습니다. 'ENTER'버튼을 사용하면 아무 일도 일어나지 않습니다.
키를 누를 때 버튼에 포커스가 있습니까? 아니오이면 키보드를 캡처하지 않습니다. 또한 키 입력 이벤트는 버튼에 포커스가 설정되었을 때만 발생하므로 Enter 키를 누르면 클릭 이벤트가 발생합니다. – Gusman
키에 포커스를 추가하는 방법은 무엇입니까? – MarvinR
버튼이 정말로 필요한가요? 내 말은, 양식에 KeyPreview 속성을 true로 설정 한 다음 키를 누를 수 있다는 것입니다. – Gusman