0

当我的标签有焦点并且有人点击“Enter”时,我试图让这个子执行这是我到目前为止的代码......

Private Sub AssignOwnersLabel_Click() Handles AssignOwnersLabel.Click
    Dim repository As OwnerRepositorySvc.OwnerRepositoryClient = Nothing

    For Each programRow As DataGridViewRow In ProgramOwnerFill.SelectedRows
        programRow.Cells(0).Value = AssignOwnersTXTBox.Text
    Next

    repository = OpenRepository()
    repository.SaveOwners(_ds)
    _ds.AcceptChanges()
    CloseRepository(repository)

    Dim dataview As DataView = _ds.ProgramOwners.DefaultView

    dataview.Sort = _ds.ProgramOwners.EmployeeIDColumn.ColumnName
    Me.ProgramOwnersBindingSource.DataSource = dataview

End Sub

我认为要让它工作,我需要用“keychar”做一些事情,但我不确定它会是什么样子。感谢帮助!

4

1 回答 1

0

要确定用户是否按下了回车键,请执行以下操作:

Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
    If e.KeyCode = Keys.Enter Then
        ' Put logic here for when the user pressed enter
    End if
End Sub

KeyPress注意:有几个键类型事件,例如KeyDownKeyUp

于 2013-08-06T19:36:32.700 回答