我想在vb.net的datagridview中输入key work作为tab键 [英] i want enter key work as tab key in datagridview in vb.net

查看:126
本文介绍了我想在vb.net的datagridview中输入key work作为tab键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在vb.net的datagridview中输入密钥工作作为tab键

解决方案

 私人 EditRow 作为 整数 = -1 
私有 Sub DataGridView1_EditingControlShowing( ByVal sender 作为 对象 ByVal e 正如 System.Windows.Forms.DataGridViewEditingControlShowingEventArgs)句柄 DataGridView1.EditingControlShowing
EditRow = DataGridView1.CurrentRow.Index
结束 Sub
私有 Sub DataGridView1_KeyDown( ByVal 发​​件人作为系统。对象 ByVal e As System.Windows.Forms.KeyEventArgs)句柄 DataGridView1.KeyDown

如果 e.KeyCode = Keys。返回 然后
如果 DataGridView1.CurrentRow.Index< DataGridView1.RowCount - 1 AndAlso _
DataGridView1.CurrentCell.ColumnIndex = DataGridView1.ColumnCount - < span class =code-digit> 1 然后
DataGridView1.CurrentCell = DataGridView1( 0 ,DataGridView1.CurrentRow.Index + 1
' SendKeys.Send({TAB})
SendKeys 。发送({UP})
否则
Dim cur_cell As DataGridViewCell = DataGridView1.CurrentCell
Dim col 作为 整数 = cur_cell.ColumnIndex
col =(col + 1 Mod DataGridView1.Columns。数
cur_cell = DataGridView1.CurrentRow.Cells(col)
DataGridView1.CurrentCell = cur_cell
结束 如果
e.Handled = True

End 如果
结束 Sub

私有 flag_cell_edited 作为 Boolean
私有 currentRow 作为 整数
私有 currentColumn 作为 整数


私有 Sub DataGridView1_CellEndEdit( ByVal sender As 系统。对象 ByVal e 作为 System.Windows.Forms.DataGridViewCellEventArgs)句柄 DataGridView1.CellEndEdit
SendKeys.Send( < span class =code-string> {TAB}


结束 Sub


私有 Sub DataGridView1_SelectionChanged( ByVal sender As System。 Object ,< span class =code -keyword> ByVal e As System.EventArgs)句柄 DataGridView1.SelectionChanged
如果 EditRow> = 0 那么
Dim new_row 作为 整数 = EditRow
EditRow = -1
DataGridView1.CurrentCell = DataGridView1.Rows(new_row).Cells(DataGridView1.CurrentCell.ColumnIndex)
End 如果

结束 Sub


大家好,

请试试这个

 GRIDVIEW1.CurrentCell = GRIDVIEW1.Rows(GRIDVIEW1.Rows.Count -1).Cells(Column_Name.Name)





祝你好运


i want enter key work as tab key in datagridview in vb.net

解决方案

Private EditRow As Integer = -1
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
        EditRow = DataGridView1.CurrentRow.Index
    End Sub
    Private Sub DataGridView1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
       
        If e.KeyCode = Keys.Return Then
            If DataGridView1.CurrentRow.Index < DataGridView1.RowCount - 1 AndAlso _
                DataGridView1.CurrentCell.ColumnIndex = DataGridView1.ColumnCount - 1 Then
                DataGridView1.CurrentCell = DataGridView1(0, DataGridView1.CurrentRow.Index + 1)
                'SendKeys.Send("{TAB}")
                'SendKeys.Send("{UP}")
            Else
                Dim cur_cell As DataGridViewCell = DataGridView1.CurrentCell
                Dim col As Integer = cur_cell.ColumnIndex
                col = (col + 1) Mod DataGridView1.Columns.Count
                cur_cell = DataGridView1.CurrentRow.Cells(col)
                DataGridView1.CurrentCell = cur_cell  
            End If
            e.Handled = True

        End If
    End Sub

    Private flag_cell_edited As Boolean
    Private currentRow As Integer
    Private currentColumn As Integer


    Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
        SendKeys.Send("{TAB}")
   
    End Sub


    Private Sub DataGridView1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
        If EditRow >= 0 Then
            Dim new_row As Integer = EditRow
            EditRow = -1
            DataGridView1.CurrentCell = DataGridView1.Rows(new_row).Cells(DataGridView1.CurrentCell.ColumnIndex)
        End If

    End Sub


Hi all,
Please try this

GRIDVIEW1.CurrentCell = GRIDVIEW1.Rows(GRIDVIEW1.Rows.Count -1).Cells(Column_Name.Name)



good luck


这篇关于我想在vb.net的datagridview中输入key work作为tab键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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