Results 1 to 2 of 2

Thread: On enter key press in TextBox on childform , reply from ProcessCMDKey of MDIParent

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2022
    Posts
    15

    Question On enter key press in TextBox on childform , reply from ProcessCMDKey of MDIParent

    I have some simple program code on Main form (which is MDIParent) to capture the Keys and running some Methods.

    I have another form (which is MDIchild) in this Program in which I am using TextBox_Keydown event to show/Hide one DGV(on Panel).
    I want that On Pressing Enter Key, Value selected in DGV must be Copied to Textbox, but actually on Pressing Enter Key “ProcessDialogKey” Function, which is written in MainForm Logic is running.
    I am not able to understand why this is happening, May someone help?

    Code:
    ''Code in MDIParent MainForm is as under
    Protected Overrides Function ProcessCmdKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
    
                Select Case keyData
                Case Keys.Enter
                    ‘ Some logic here 
                    MastripMenuItem.ShowDropDown()
                    Return True 
    
                Case Keys.Escape
                    EXITToolStripMenuItem1.PerformClick()
                    Return True
    
                Case (Keys.Left + Keys.Shift)
                    DTroutine() ‘ Some Method for Database Modification
                    Return True
    
                Case Else
                    Return MyBase.ProcessDialogKey(keyData)
            End Select
            
            Return MyBase.ProcessDialogKey(keyData) 
        End Function
    
    'Code in MDIChild Form is as under
    
    Private Sub TxtParty_KeyDown(sender As Object, e As KeyEventArgs) Handles TxtParty.KeyDown
            If DGVPartySearch.RowCount = 0 Then e.Handled = False : Exit Sub
     
            If PanelDGV.Visible = True Then
               
                '                nRowDGParty is rowindex on DGVPartySearch
                DGVPartySearch.ClearSelection()
                DGVPartySearch.Rows(nRowDGParty).Selected = True
                TxtParty.Focus()
            End If
     
                If e.KeyData = Keys.Down Then
                If PanelDGV.Visible = False Then
                    PanelDGV.Visible = True
                   
                    e.Handled = e.SuppressKeyPress = True
                    Exit Sub
                Else
                    If nRowDGParty + 1 < DGVPartySearch.RowCount Then
                        DGVPartySearch.ClearSelection()
                        nRowDGParty += 1
                        DGVPartySearch.Rows(nRowDGParty).Selected = True
                        TxtParty.Focus()
                    End If
                    'e.Handled = True
                    e.Handled = e.SuppressKeyPress = True
                End If
                Exit Sub
            End If
            
            If e.KeyData = Keys.Enter OrElse e.KeyData = Keys.Return Then
               If PanelDGV.Visible = True Then
                    Dim AccName As String = DGVPartySearch.Item(0, nRowDGParty).Value
                              TxtParty.Text = AccName
                              TxtParty.Select(TxtParty.Text.Length, 0)
     
                    PanelDGV.Hide()
                    e.Handled = e.SuppressKeyPress = True
                    Exit Sub
                End If
            End If
            e.Handled = False
        End Sub
    Last edited by dday9; Sep 7th, 2022 at 04:03 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width