Reputation: 9074
I have on large grid of data about 25000 rows. [Windows Application]
In that i am trying to implement functionality like, when i press enter key i can open new window. In that new window i am showing data for the record for which i pressed enter button in terms of text boxes and labels. But unfortunately i did not found any relative event for that. when i press enter button active selected row moves to the next record.
I also want to know if there is any functionality such that when i load the window[Grid] by default first record should get selected.
I have tried different events such as
private void gvTradeFile_RowEnter(object sender, DataGridViewCellEventArgs e)
{
splitPopUp objSplit = new splitPopUp();
objSplit.Show();
}
Not Worked.
private void gvTradeFile_Enter(object sender, EventArgs e)
{
splitPopUp objSplit = new splitPopUp();
objSplit.Show();
}
This also not worked.
I refered http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/6a73013f-4440-4d45-a322-63c4cae1bb39/ this link but got nothing out of it.
Is there any idea related to implementing this functionality?
Upvotes: 1
Views: 2364
Reputation: 18472
You need to handle grid's KeyDown
event:
private void gvTradeFile_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
var row = dataGridView1.CurrentRow; // retreive the current row
// show the form
// ...
}
}
The Enter
event occurs when keyboard focus enters into the grid, and RowEnter
event occurs when a row receives input focus. These events have no relation to the Enter key.
Upvotes: 3