Results 1 to 2 of 2

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

  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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: On enter key press in TextBox on childform , reply from ProcessCMDKey of MDIParen

    In an MDI application, the child form is part of the parent. The parent has an MdiClient control added to it - that's why the form changes to a grey colour - and the child forms are then added to that as controls. That ProcessCmdKey method is invoked just as it would be for any other child controls. You'll need to add some code to check where focus actually is, i.e. on the parent or a child. I would expect that using the ActiveControl property would be a big part of that, but I haven't tested to see exactly what would work and what wouldn't.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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