Hi Team,
On the cell end edit mode the enter key event is working fine and it is firing the keydown event from the CellEditorInitialized and gets updated with the given value on the other grid. - This is the actual process.
Is it possible to have the same functionality while pressing the tab key?
Video Link
5 Answers, 1 is accepted
Hello, Rick,
The provided sample video is greatly appreciated for understanding better the scenario you have. However, it is not very clear what is the exact code implementation that you have on your end.
I suppose that in the CellEditorInitialized event you subscribe to some event of the activated editor. Once this handled event is fired, e.g. when pressing Enter, you execute certain logic, e.g. updating the respective cell's value for the top grid.
In this case, I would recommend you to follow another approach. Don't handle any events on the editor itself. It is suitable to use the RadGridView.CellValueChanged event. Since this event fires when the value of a cell has been changed, you will handle cell's value changing as a result of both keys pressing, TAB and ENTER, along with focusing another cell as well. Then you can perform the logic you have.
However, if it is not the case, it would be greatly appreciated if you can provide more details about the precise case. Thus, we would be able to think about a suitable solution.
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Hi Dess,
Thanks for your reply. With the provided solution we are not sure from where the current key event is taken. Can you please provide us a sample code snippet for it?
We have written code on key down event on cell editor initialized.Can you please let us know if we can use the same code on cellvalueChanged ?
Private Sub rdgvHGrid_CellEditorInitialized(sender As Object, e As GridViewCellEventArgs) Handles rdgvHGrid.CellEditorInitialized
If Not processing Then
Dim tbEditor As RadTextBoxEditor = TryCast(Me.rdgvHGrid.ActiveEditor, RadTextBoxEditor)
If Not tbEditor Is Nothing Then
processing = 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)
Dim T As Integer
T = rdgvHGrid.CurrentColumn.Index
' If hit delete key
If rdgvHGrid.CurrentColumn.Index > 0 Or rdgvHGrid.CurrentColumn.Index < 6 Then
If e.KeyCode = Keys.Delete Then
'.Columns(.Col).Text = 0
'.RefetchRow
ArrayItemH(rdgvHGrid.CurrentRow.Index)(rdgvHGrid.CurrentColumn.Index) = 0
rdgvHGrid.DataSource = ArrayItemH
End If
End If
' If the user hits the arrow down key
'If e.KeyCode = Keys.Down Then
If e.KeyCode = 13 Then
rdgvHGrid.EndEdit()
rdgvHGrid.BeginEdit()
' Update array
ArrayItemH(rdgvHGrid.CurrentRow.Index)(1) = rdgvHGrid.CurrentRow.Cells(1).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(2) = rdgvHGrid.CurrentRow.Cells(2).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(3) = rdgvHGrid.CurrentRow.Cells(3).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(4) = rdgvHGrid.CurrentRow.Cells(4).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(5) = rdgvHGrid.CurrentRow.Cells(5).Value
' Update Main grid
If rdgvHGrid.CurrentColumn.Index > 0 And rdgvHGrid.CurrentColumn.Index < 6 Then UpdateMain()
' .Col = T
End If
' Update array
If e.KeyCode = Keys.Tab Or e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Up Then
ArrayItemH(rdgvHGrid.CurrentRow.Index)(rdgvHGrid.CurrentColumn.Index) = rdgvHGrid.CurrentRow.Cells(rdgvHGrid.CurrentColumn.Index).Value
' Update Main grid
If T > 0 And T < 6 Then UpdateMain()
' rdgvHGrid.CurrentColumn.Index = T
ArrayItemH(rdgvHGrid.CurrentRow.Index)(1) = rdgvHGrid.CurrentRow.Cells(1).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(2) = rdgvHGrid.CurrentRow.Cells(2).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(3) = rdgvHGrid.CurrentRow.Cells(3).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(4) = rdgvHGrid.CurrentRow.Cells(4).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(5) = rdgvHGrid.CurrentRow.Cells(5).Value
' Update Main grid
If rdgvHGrid.CurrentColumn.Index > 0 And rdgvHGrid.CurrentColumn.Index < 6 Then UpdateMain()
'.Col = T
End If
End Sub
Hi Dess,
Thanks for your reply. With the provided solution we are not sure from where the current key event is taken. Can you please provide us a sample code snippet for it?
We have written code on key down event on cell editor initialized.Can you please let us know if we can use the same code on cellvalueChanged ?
Private Sub rdgvHGrid_CellEditorInitialized(sender As Object, e As GridViewCellEventArgs) Handles rdgvHGrid.CellEditorInitialized
If Not processing Then
Dim tbEditor As RadTextBoxEditor = TryCast(Me.rdgvHGrid.ActiveEditor, RadTextBoxEditor)
If Not tbEditor Is Nothing Then
processing = 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)
Dim T As Integer
T = rdgvHGrid.CurrentColumn.Index
' If hit delete key
If rdgvHGrid.CurrentColumn.Index > 0 Or rdgvHGrid.CurrentColumn.Index < 6 Then
If e.KeyCode = Keys.Delete Then
'.Columns(.Col).Text = 0
'.RefetchRow
ArrayItemH(rdgvHGrid.CurrentRow.Index)(rdgvHGrid.CurrentColumn.Index) = 0
rdgvHGrid.DataSource = ArrayItemH
End If
End If
' If the user hits the arrow down key
'If e.KeyCode = Keys.Down Then
If e.KeyCode = 13 Then
rdgvHGrid.EndEdit()
rdgvHGrid.BeginEdit()
' Update array
ArrayItemH(rdgvHGrid.CurrentRow.Index)(1) = rdgvHGrid.CurrentRow.Cells(1).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(2) = rdgvHGrid.CurrentRow.Cells(2).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(3) = rdgvHGrid.CurrentRow.Cells(3).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(4) = rdgvHGrid.CurrentRow.Cells(4).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(5) = rdgvHGrid.CurrentRow.Cells(5).Value
' Update Main grid
If rdgvHGrid.CurrentColumn.Index > 0 And rdgvHGrid.CurrentColumn.Index < 6 Then UpdateMain()
' .Col = T
End If
' Update array
If e.KeyCode = Keys.Tab Or e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Up Then
ArrayItemH(rdgvHGrid.CurrentRow.Index)(rdgvHGrid.CurrentColumn.Index) = rdgvHGrid.CurrentRow.Cells(rdgvHGrid.CurrentColumn.Index).Value
' Update Main grid
If T > 0 And T < 6 Then UpdateMain()
' rdgvHGrid.CurrentColumn.Index = T
ArrayItemH(rdgvHGrid.CurrentRow.Index)(1) = rdgvHGrid.CurrentRow.Cells(1).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(2) = rdgvHGrid.CurrentRow.Cells(2).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(3) = rdgvHGrid.CurrentRow.Cells(3).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(4) = rdgvHGrid.CurrentRow.Cells(4).Value
ArrayItemH(rdgvHGrid.CurrentRow.Index)(5) = rdgvHGrid.CurrentRow.Cells(5).Value
' Update Main grid
If rdgvHGrid.CurrentColumn.Index > 0 And rdgvHGrid.CurrentColumn.Index < 6 Then UpdateMain()
'.Col = T
End If
End Sub
Thank you for sharing the code snippet.
According to the provided piece of code, it seems that after you press Keys.Enter, an item gets updated by the values of the current row's cells. I believe that this part of the code can be successfully moved to the CellValueChanged event. Thus, no matter whether Tab or Enter key is pressed, once the value is committed to the cell, the CellValueChanged event will be fired and you will be able to store the changes to the item you need.
However, if you still prefer the way of handling the editor's key, note that it is necessary to subscribe to the PreviewKeyDown event of the hosted TextBox inside the editor:
Sub New()
InitializeComponent()
AddHandler Me.RadGridView1.CellEditorInitialized, AddressOf RadGridView1_CellEditorInitialized
End Sub
Private Sub RadGridView1_CellEditorInitialized(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs)
Dim tbEditor As RadTextBoxEditor = TryCast(e.ActiveEditor, RadTextBoxEditor)
If Not tbEditor Is Nothing Then
Dim tbElement As RadTextBoxEditorElement = CType(tbEditor.EditorElement, RadTextBoxEditorElement)
RemoveHandler tbElement.TextBoxItem.TextBoxControl.PreviewKeyDown, AddressOf TextBoxControl_PreviewKeyDown
AddHandler tbElement.TextBoxItem.TextBoxControl.PreviewKeyDown, AddressOf TextBoxControl_PreviewKeyDown
End If
End Sub
Private Sub TextBoxControl_PreviewKeyDown(sender As Object, e As PreviewKeyDownEventArgs)
If e.KeyData = Keys.Enter Then
Console.WriteLine("Enter")
ElseIf e.KeyData = Keys.Tab Then
Console.WriteLine("Tab")
End If
End Sub
Should you have further questions please let me know.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.
Hi Dess,
Thank you so much for your reply. This is working good.