我使用datagridview,我想通过用户输入进入下一行 [英] I use datagridview and I want to come next line with enter with user input

查看:67
本文介绍了我使用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;
           }
       }


这篇关于我使用datagridview,我想通过用户输入进入下一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆