I'm trying to get this sub to execute when my lable has focus and someone clicks "Enter" This is the code I have so far...

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

I think to get this to work I need to do something with "keychar" but I'm not sure how that would look. Thanks for help!

有帮助吗?

解决方案

To find out if the user pressed the enter key, do this:

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

Note: There are several key-type events, such as KeyPress, KeyDown and KeyUp.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top