Link to home
Start Free TrialLog in
Avatar of mahmood66
mahmood66Flag for United Arab Emirates

asked on

Capture keypressed event within Datagrid cell

i am displaying List box when ever the cursor in one of the cell of datagrid.Now i want to filter the listbox according to the key pressed inside the Datagrid.can i catch this event.
Avatar of sunithnair
sunithnair

You can use javascript to catch keypress. You can then implement the KeyPressEvent in javascript and postback to the server to filter the listbox


<input type="text" name="test" onkeypress="KeyPressEvent()">

Open in new window

Avatar of mahmood66

ASKER

how to use this can you give the complete code
dear i am using vb.net 2005 and  datagrid view control
Avatar of Howard Cantrell
"i want to filter the listbox according to the key pressed inside the Datagrid"
Can you give more detail of what you want?
Keypress from each cell? or Keypress from the listbox only?
ok i am i using datagrid in which i am displaying listbox on the click event of the cell as like a dropdown combo in the datagrid.now i want catch the keypress event inside the cell of the datagrid which will result in filtering the listbox accordingly.filtering is the next step .First i want to know whch letter is pressed on the keyboard by the user.
I hope everything is clear
ASKER CERTIFIED SOLUTION
Avatar of mahmood66
mahmood66
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry I have been real busy.
here is a  piece of code that see's the keypress on the form.
I was using it for a Horz. Scroll movement.
All you have to do is change the code for the keys you want to search for.
I hope this will help you in your search for the listbox keypress group.
   Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
        Const WM_KEYDOWN As Integer = &H100
        Const WM_SYSKEYDOWN As Integer = &H104
 
        If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
            Select Case (keyData)
                Case System.Windows.Forms.Keys.Home
                    Me.HBar.Value = 1
                Case System.Windows.Forms.Keys.End
                    Me.HBar.Value = Me.MaxRecordCount
                Case System.Windows.Forms.Keys.PageUp
                    If (Me.HBar.Value + 20) >= Me.MaxRecordCount Then
                        Me.HBar.Value = Me.MaxRecordCount
                    Else
                        Me.HBar.Value += 20
                    End If
                Case System.Windows.Forms.Keys.PageDown
                    If (Me.HBar.Value - 20) <= 1 Then
                        Me.HBar.Value = 1
                    Else
                        Me.HBar.Value -= 20
                    End If
                Case System.Windows.Forms.Keys.Right
                    If Me.HBar.Value = Me.MaxRecordCount Then
                    Else
                        Me.HBar.Value = Current_Row + 1
                    End If
                Case System.Windows.Forms.Keys.Left
                    If Me.HBar.Value = 1 Then
                    Else
                        Me.HBar.Value = Current_Row - 1
                    End If
                Case System.Windows.Forms.Keys.Up
                    If (Me.HBar.Value + 5) >= Me.MaxRecordCount Then
                        Me.HBar.Value = Me.MaxRecordCount
                    Else
                        Me.HBar.Value += 5
                    End If
                Case System.Windows.Forms.Keys.Down
                    If (Me.HBar.Value - 5) <= 1 Then
                        Me.HBar.Value = 1
                    Else
                        Me.HBar.Value -= 5
                    End If
            End Select
            Current_Row = Me.HBar.Value
        End If
    Return MyBase.ProcessCmdKey(msg, keyData)
    End Function

Open in new window