我有一個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