This is a migrated thread and some comments may be shown as answers.

F1 KeyDown Event

1 Answer 144 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Terry
Top achievements
Rank 1
Terry asked on 06 Apr 2011, 02:51 PM
Hello,

I can't seem to trap any Function keys while editing a cell on the radGridView. Could you provide any clues where I am going wrong? I have practically copied the code from your help documentation. If I press Ctrl+L then all works fine.

Regards

Terry

Public Class Form1
  
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  
  
        Me.KeyPreview = True
  
        Dim x As Boolean
        x = LogIntoSQL()
  
        If x = True Then
            Try
                myList = New BindingList(Of CompanyHistory)()
                LoadNewCompanyHistory()
                RadGridView1.DataSource = myList
  
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
  
         
  
    End Sub
  
     
    Private tbSubscribed As Boolean = False
  
    Private Sub radGridView1_CellEditorInitialized(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs)
        Dim tbEditor As RadTextBoxEditor = TryCast(Me.RadGridView1.ActiveEditor, RadTextBoxEditor)
        If Not tbEditor Is Nothing Then
            If (Not tbSubscribed) Then
                tbSubscribed = True
                Dim tbElement As RadTextBoxEditorElement = CType(tbEditor.EditorElement, RadTextBoxEditorElement)
                AddHandler tbElement.KeyDown, AddressOf tbElement_KeyDown
            End If
        End If
    End Sub
  
    Private Sub tbElement_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
        If e.Control Then
            If e.KeyCode = Keys.F1 Then
                CType(sender, RadTextBoxEditorElement).Text = "F1"
            End If
  
            If e.KeyCode = Keys.F2 Then
                CType(sender, RadTextBoxEditorElement).Text = "F2"
            End If
  
            If e.KeyCode = Keys.L Then
                CType(sender, RadTextBoxEditorElement).Text = "LLLL"
            End If
  
        End If
  
  
    End Sub
  
    Public Sub New()
  
        ' This call is required by the designer.
        InitializeComponent()
  
        ' Add any initialization after the InitializeComponent() call.
        AddHandler RadGridView1.CellEditorInitialized, AddressOf radGridView1_CellEditorInitialized
    End Sub
End Class

 

 

 

 

 

 

 

 



1 Answer, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 06 Apr 2011, 03:53 PM
Hello Terry,

The reason why you are not receiving key press events is because are not sent to the editor element, instead the editor element has a property called TextBoxItem. In order to catch those events you should handle the KeyDown event of the base TextBox so in your case: tbElement.TextBoxItem.KeyDown.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
Tags
GridView
Asked by
Terry
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Share this question
or