我使用datagridview,我想通过用户输入进入下一行
问题描述:
我在datagridview中创建购买,我从列表中获得了一些来自数据库的输入,有些来自用户输入密钥。当用户在第一行填写数据时,他需要填写另一个项目到2行我怎么办.net c #windows应用程序
我有什么尝试过:
i使用输入密钥但是当到达datagridview焦点的最后一列时,焦点不会出现在第二行1列
i am creating purchase in datagridview and i had some input from database by list and some from user with enter key. when user fill data in 1 st line he need to fill another item to 2 line how i can do in .net c # windows application
What I have tried:
i use enter key but when comes to last column in datagridview focus does not come on second line 1 column
答
在keydown处理代码尝试如下:
Handle code in keydown try like this:
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
int columnindex = dataGridView1.CurrentCell.ColumnIndex;
int rowindex = dataGridView1.CurrentCell.RowIndex;
if (columnindex < dataGridView1.ColumnCount - 1)
{
columnindex++;
}
else
{
columnindex = 0;
rowindex++;
}
if (rowindex == dataGridView1.RowCount)
dataGridView1.Rows.Add();
dataGridView1.CurrentCell = dataGridView1[columnindex, rowindex];
e.Handled = true;
}
}