【发布时间】:2014-03-19 08:42:29
【问题描述】:
我有一个用 DataTable 填充的 DataGridView,有 10 列。当我单击 Enter 键时从一行移动到另一行时,我有一个场景,然后我需要选择该行并且需要具有该行值。
但是在这里,当我选择第 n 行时,它会自动移动到 n+1 行。
请帮帮我...
在页面加载事件中:
SqlConnection con =
new SqlConnection("Data Source=.;Initial Catalog=MHS;User ID=mhs_mt;Password=@mhsinc");
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());
}
【问题讨论】:
-
你想按回车键然后选择移动到下一行啊?
-
不,我想要当前行本身
标签: c# .net winforms c#-4.0 datagridview