如何将专注于下一个单元格在一个DataGridView上的回车键preSS事件 [英] How to move focus on next cell in a datagridview on Enter key press event

查看:135
本文介绍了如何将专注于下一个单元格在一个DataGridView上的回车键preSS事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,我对Windows应用程序使用C#的工作。我使用一个DataGridView显示的记录。我需要的功能是,当我preSSEnter键重点应该进入下一个单元格(同一行的列)。如果它是在网格中的最后一列则重点应转到下一行的第一列中。我使用已经试过

  SendKeys.Send({TAB})

在datagridview1_KeyDown和datagridview1_Key preSS事件。但重点是斜着向下移动。请帮我解决这个问题。


解决方案

 私人无效dataGridView1_KeyDown(对象发件人,发送KeyEventArgs E)
        {
            如果(e.Key code == Keys.Enter)
            {
                e.Sup pressKey preSS = TRUE;
                INT iColumn = dataGridView1.CurrentCell.ColumnIndex;
                INT iRow = dataGridView1.CurrentCell.RowIndex;
                如果(iColumn == dataGridView1.Columns.Count-1)
                    dataGridView1.CurrentCell = dataGridView1 [0,iRow + 1〕;
                其他
                    dataGridView1.CurrentCell = dataGridView1 [iColumn + 1,iRow];            }
        }

Friends, I'm working on windows application using C#. I'm using a datagridview to display records. The functionality I need is when I press "Enter" key the focus should go to the next cell(column of same row). If it's the last column in the grid then the focus should go to the first column of the next row. I've already tried using

    SendKeys.Send("{Tab}")

in datagridview1_KeyDown and datagridview1_KeyPress event. But focus is moving diagonally down. Please help me to solve this.

解决方案

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {                
                e.SuppressKeyPress=true;
                int iColumn = dataGridView1.CurrentCell.ColumnIndex;
                int iRow = dataGridView1.CurrentCell.RowIndex;
                if (iColumn == dataGridView1.Columns.Count-1)
                    dataGridView1.CurrentCell = dataGridView1[0, iRow + 1];
                else
                    dataGridView1.CurrentCell = dataGridView1[iColumn + 1, iRow];

            }
        }

这篇关于如何将专注于下一个单元格在一个DataGridView上的回车键preSS事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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