在数据网格视图中输入选项卡 [英] enter as tab IN datagridview

查看:90
本文介绍了在数据网格视图中输入选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我正在浏览DGV时,他点击进入更改列。

搜索了网络,但我发现的例子没有用,如果你们可以帮助我的话。



我感谢你。

我试过了,但这不是我需要的东西

When I''m browsing the DGV that when he hit enter change column.
Have searched the net but the examples I found did not work, if you guys can help me.

I thank you.
I''ve tried, but it''s not what I need

If e.KeyCode = Keys.Enter Then
    SendKeys.Send (Keys.Tab)
end If



我已经尝试了另一个下面的工作,但当我使用一个按钮输入它像tab一样工作,或者表单已经打开,我想在 DataGridView中保持活跃


I''ve tried another one below it worked, but when I use a button to enter it works like tab, or form is turned in, I want to just stay active in DataGridView.

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
    If (Me.DataGridView1.Focused OrElse Me.DataGridView1.EditMode) AndAlso keyData = Keys.Enter Then
        SendKeys.Send("{TAB}")
        Return True
    End If

    Return MyBase.ProcessCmdKey(msg, keyData)

End Function



不是我需要的是什么。



需要每当我​​按下回车键时,它会进入该单元格到单元格和终点线旁边的列,而不是向下。



我在互联网上发现这个,几乎但仍然不是我需要的。


is not what I need.

need that every time I press enter, it will enter that cell to cell and the column next to the finish line, not down.

I found this on the internet, it was almost but still not what I need.

Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean


        If keyData = Keys.Enter Then
            If TypeOf Me.ActiveControl Is DataGridViewTextBoxEditingControl OrElse _
              TypeOf Me.ActiveControl Is DataGridViewComboBoxEditingControl Then


                If dgv1.CurrentCell.ColumnIndex < dgv1.ColumnCount - 1 Then


                    dgv1.CurrentCell = dgv1.Rows(dgv1.CurrentCell.RowIndex).Cells(dgv1.CurrentCell.ColumnIndex + 1)


                Else
                    Return MyBase.ProcessCmdKey(msg, keyData)
                End If
            End If
        Else
            Return MyBase.ProcessCmdKey(msg, keyData)
        End If
    End Function

event datagrid
    Private Sub DataGridView_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView.CellEnter

        If e.ColumnIndex = 1 Then
            dgv1.BeginEdit(True)

        End If
    End Sub

推荐答案

有一个漂亮的答案很好在MSDN上这里 [ ^ ]。

There is a pretty good answer right here on MSDN[^].
Class MyDataGridView
    Inherits DataGridView

    Protected Overloads Overrides Function ProcessDialogKey(ByVal keyData As Keys) As Boolean
        If keyData = Keys.Enter Then
            MyBase.ProcessTabKey(Keys.Tab)
            Return True
        End If
        Return MyBase.ProcessDialogKey(keyData)
    End Function

    Protected Overloads Overrides Function ProcessDataGridViewKey(ByVal e As KeyEventArgs) As Boolean
        If e.KeyCode = Keys.Enter Then
            MyBase.ProcessTabKey(Keys.Tab)
            Return True
        End If
        Return MyBase.ProcessDataGridViewKey(e)
    End Function

End Class

希望有帮助:)


我在KeyDown中使用此代码DatGridView的事件:

I use this code in my KeyDown event for the DatGridView:
Private Sub dgvMyGrid_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgvMyGrid.KeyDown
    Select Case e.KeyCode
        Case Keys.Enter
            e.Handled = True
            SendKeys.Send("{TAB}")
        End Select
    End Sub





我将DataGridView.EditMode设置为 EditOnEnter 。您可能必须使用该设置才能达到您想要的效果。



I have my DataGridView.EditMode set to EditOnEnter. You may have to play with that setting to get it the way you want.


Private Const WM_KEYDOWN =&H100



受保护的覆盖函数ProcessKeyPreview(ByRef m As System.Windows.Forms.Message)As Boolean

Dim keyCode As Keys = CType(m.WParam.ToInt32()和Keys.KeyCode,Keys)

如果m.Msg = WM_KEYDOWN和keyCode = Keys.Enter那么

SendKeys.Send({TAB})

返回True

结束如果

返回MyBase.ProcessKeyPreview(m)

结束函数
Private Const WM_KEYDOWN = &H100

Protected Overrides Function ProcessKeyPreview(ByRef m As System.Windows.Forms.Message) As Boolean
Dim keyCode As Keys = CType(m.WParam.ToInt32() And Keys.KeyCode, Keys)
If m.Msg = WM_KEYDOWN And keyCode = Keys.Enter Then
SendKeys.Send("{TAB}")
Return True
End If
Return MyBase.ProcessKeyPreview(m)
End Function


这篇关于在数据网格视图中输入选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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