我有一个DataGridView填充DataTable,有10列。当我单击Enter键时从一行移动到另一行时,我有一个场景,那么我需要选择该行并需要具有该行值。DataGridView“输入”键事件处理
但在这里,当我选择ň个排那么它会自动移动到N + 1行。
请帮我在这...
在页面加载事件:
SqlConnection con =
new SqlConnection("Data Source=.;Initial Catalog=MHS;User ID=mhs_mt;[email protected]");
DataSet ds = new System.Data.DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from MT_INVENTORY_COUNT", con);
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
然后,
private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (Char)Keys.Enter)
{
int i = dataGridView1.CurrentRow.Index;
MessageBox.Show(i.ToString());
}
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int i = dataGridView1.CurrentRow.Index;
MessageBox.Show(i.ToString());
}
做你想按回车键然后选择移动到下一排啊? – Sathish
不,我想当前行本身 – MSanika