如何使用vb.net在keydown事件的datagridview中从一个单元格聚焦到另一个单元格 [英] How to focus from one cell to another cell in datagridview on keydown event using vb.net

查看:102
本文介绍了如何使用vb.net在keydown事件的datagridview中从一个单元格聚焦到另一个单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Friends



我在datagridview中有一个关注焦点的查询。



我有一个datagridview,我想在keydown事件中从单元格1移动到单元格2,并检查单元格1是否为空,然后移动到单元格2否则移动到单元格3.



我的代码适用于列,但它移动到下一行。



这里是关键事件的代码



Hello Friends

I have a query related to focus on cell in datagridview.

Acutally i have a datagridview and i want to move from cell 1 to cell 2 on keydown event and also check if the cell 1 is not blank then it moves to cell 2 otherwise move to cell 3.

My code works fine for column but it moves to next row.

here is my code on key down event

If e.KeyCode = Keys.Enter Then
            Select Case DataGridView1.CurrentCell.ColumnIndex
                Case 1
                    If Len(Trim(DataGridView1.CurrentRow.Cells(1).Value)) > 0 Then
                        DataGridView1.CurrentCell = DataGridView1(2, DataGridView1.CurrentCell.RowIndex)
                        DataGridView1.Focus()
                    Else
                        DataGridView1.CurrentCell = DataGridView1(3, DataGridView1.CurrentCell.RowIndex)
                    End If
                Case 2
                    DataGridView1.CurrentCell = DataGridView1(3, DataGridView1.CurrentCell.RowIndex)
                Case 3
                    DataGridView1.CurrentCell = DataGridView1(4, DataGridView1.CurrentCell.RowIndex)
                Case 4
                    DataGridView1.CurrentCell = DataGridView1(5, DataGridView1.CurrentCell.RowIndex)
                Case 5
                    DataGridView1.CurrentCell = DataGridView1(1, DataGridView1.CurrentCell.RowIndex + 1)
            End Select
        End If





它有效但转到下一行。





请尽快帮助我。



谢谢&问候



it works but move to next rows .


Please help me out as soon as possible.

Thanks & Regards

推荐答案

它将移动到下一行,因为这是ENTER键通常所做的。你需要告诉它你自己处理它,它应该跳过它。为此,您需要在确定它是Enter键后立即添加此声明。



It will move to the next row because that's what the ENTER key normally does. You need to tell it that you are handling it on your own and it should skip that. To do that, you need to add this statement right after you've determined that it's the Enter key.

e.Handled = True


这篇关于如何使用vb.net在keydown事件的datagridview中从一个单元格聚焦到另一个单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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