CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2001
    Location
    Minneapolis, MN, USA
    Posts
    150

    Handling Keypress Or KeyDown Events

    Has anyone worked with Keypress and/or KeyDown Events? I'm trying to use these events with a DataGrid. I would like to arrow up/down until I get to the row I want and select the row by using one of the above events. BUT I'm having trouble!

    It's seems like you only can use the KeyDown Event when you have the whole row selected and not just one cell in a row. SO to avoid this problem I tried a DataGrid.LocationChange event to select the whole row when arrowing down or up. I figured you could just get the Current Row by getting the row via CurrentRowIndex or CurrentCell and then doing a DataGrid.Select(CurrentRow) when changing the Location....but I can't get it to work...any suggestions?

  2. #2
    Join Date
    Mar 2002
    Location
    NY
    Posts
    236

    Re: Handling Keypress Or KeyDown Events

    That's not exactly what you need, but might guide you in the right direction (handling keypress for combobox):
    Code:
        Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
            If cmbConstW.Focused Or cmbConstH.Focused Then
                Select Case keyData
                    Case Keys.D0, Keys.D1, Keys.D2, Keys.D3, Keys.D4, Keys.D5, Keys.D6, Keys.D7, Keys.D8, Keys.D9, Keys.Delete, Keys.Back, Keys.Divide, 191        'accept digits only
                        Return False
                    Case Else
                        Return True
                End Select
            Else
                Return MyBase.ProcessDialogKey(keyData)
            End If
        End Function
    Can't do better (maybe, that's not even what you need) - very busy lately.
    Good luck.

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

Featured