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

GridViewDecimalColumn Up& down key

10 Answers 323 Views
GridView
This is a migrated thread and some comments may be shown as answers.
AJing
Top achievements
Rank 1
AJing asked on 13 Dec 2011, 02:56 AM
Hi:

    I want to skip to the above or the next row when I use up or down key on the gridviewdecimalcolumn.

    Now , It is not work. It is only focus the old column.

Greetings.
Look forward to your reply.
Ajing

10 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 16 Dec 2011, 10:25 AM
Hello Ajing,

Thank you for writing.

You can achieve the desired behavior by using the following approach. Subscribe to the CellEditorInitialized event and in its handler and access the GridSpinEditorElement. Set the InterceptArrowKeys to false in order to prevent the number in the decimal cell increase/decrease when using arrow keys. Then subscribe to the KeyDown of the element and in the event handler, navigate to the desired rows when the up/down keys are pressed. Here is sample code of the above:
void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    GridSpinEditor editor = e.ActiveEditor as GridSpinEditor;
    if (editor != null)
    {
        GridSpinEditorElement element = editor.EditorElement as GridSpinEditorElement;
        element.InterceptArrowKeys = false;
        element.KeyDown -= new KeyEventHandler(element_KeyDown);
        element.KeyDown += new KeyEventHandler(element_KeyDown);
    }
}
 
void element_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyData == Keys.Up)
    {
        radGridView1.GridNavigator.SelectPreviousRow(1);
    }
    if (e.KeyData == Keys.Down )
    {
        radGridView1.GridNavigator.SelectNextRow(1);
    }
}

I hope that the provided information addresses your question. Should you have any other inquiries, do not hesitate to contact us.
 
Best wishes,
Stefan
the Telerik team

Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.

0
Mark
Top achievements
Rank 2
answered on 27 Jan 2015, 04:15 PM
Stefan:  I had asked for vb.net code because the Telerik converter is not working and hasn't for a couple months.  I've been using DotNet Spider instead.  But regardless of the converter I use, the code does not convert cleanly.

These 2 lines of code in C#...
    element.KeyDown -= new KeyEventHandler(element_KeyDown);        
    element.KeyDown += new KeyEventHandler(element_KeyDown);

Convert to this in vb.net...
    element.KeyDown -= New KeyEventHandler(AddressOf element_KeyDown)
    element.KeyDown += New KeyEventHandler(AddressOf element_KeyDown)

But the compiler interprets these lines as errors because "element" (GridSpinEditorElement) has no KeyDown Event in its namespace.  Is this what VB would code as a RaiseEvent?? 

Can you please send me the VB.net code for this.  We are converting the entire app next month to C# for this very reason, but in the mean time, I have to get this working.  Please try to respond today. Thanks. 


0
Mark
Top achievements
Rank 2
answered on 27 Jan 2015, 04:27 PM
Answer to my own question....

This C# code...
      element.KeyDown -= new KeyEventHandler(element_KeyDown);
      element.KeyDown += new KeyEventHandler(element_KeyDown);

Converts to this VB.net code...
      AddHandler element.KeyDown, AddressOf element_KeyDown
0
Mark
Top achievements
Rank 2
answered on 27 Jan 2015, 06:20 PM
What is happening now is that the first down arrow key press moves to the next row, but the second down arrow key press moves 2 rows down and the 3rd press moves 4 rows down.  Is this caused by filtering or sorting or something?
0
Mark
Top achievements
Rank 2
answered on 27 Jan 2015, 07:27 PM
Answering my own question...

Here is the VB.net code that works correctly (Stefan: please update if you have something better)...

--------------------------------------------------------------------------------------

Private KeyDownisRunning As Boolean = False

Private Sub rgvFactor_CellEditorInitialized(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles rgvFactor.CellEditorInitialized
Select Case e.ActiveEditor.GetType
Case GetType(GridSpinEditor)
If KeyDownisRunning = True Then Exit Sub
Dim GseEditor As GridSpinEditor = TryCast(e.ActiveEditor, GridSpinEditor)
If Not GseEditor Is Nothing Then
Dim element As GridSpinEditorElement = TryCast(GseEditor.EditorElement, GridSpinEditorElement)
element.InterceptArrowKeys = False
AddHandler element.KeyDown, AddressOf element_KeyDown
End If
GseEditor = Nothing
End Select
End Sub

Private Sub element_KeyDown(sender As Object, e As KeyEventArgs)
KeyDownisRunning = True
If e.KeyData = Keys.Up Then
rgvFactor.GridNavigator.SelectPreviousRow(1)
End If
If e.KeyData = Keys.Down Then
rgvFactor.GridNavigator.SelectNextRow(1)
End If
KeyDownisRunning = False
End Sub
0
Stefan
Telerik team
answered on 28 Jan 2015, 11:37 AM
Hello Mark,

Please excuse me for omitting the VB.NET part. The converter is up and running (Code Converter), however, it will not convert event subscriptions (all of the converters out there doesn't do that, just in some cases). However, to the question at hand, if you notice the first line 
element.KeyDown -= new KeyEventHandler(element_KeyDown);

this unsubscribes from the event, while the following line subscribes for it. 
element.KeyDown += new KeyEventHandler(element_KeyDown);

In VB this code looks as follows:
AddHandler element.KeyDown, AddressOf element_KeyDown
RemoveHandler element.KeyDown, AddressOf element_KeyDown

More about subscribing to events in VB. NET can be found here: https://msdn.microsoft.com/en-us/library/7taxzxka.aspx.

I hope this helps.

Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Mark
Top achievements
Rank 2
answered on 28 Jan 2015, 07:04 PM
Thank you Stefan....that helps!

I'm reposting the complete "corrected" VB.net code for any future readers of this thread...

Private Sub rgvFactor_CellEditorInitialized(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles rgvFactor.CellEditorInitialized
    Select Case e.ActiveEditor.GetType
        Case GetType(GridSpinEditor)
            Dim GseEditor As GridSpinEditor = TryCast(e.ActiveEditor, GridSpinEditor)
            If Not GseEditor Is Nothing Then
                Dim element As GridSpinEditorElement = TryCast(GseEditor.EditorElement, GridSpinEditorElement)
                element.InterceptArrowKeys = False
                AddHandler element.KeyDown, AddressOf element_KeyDown
            End If
    End Select
End Sub
 
Private Sub element_KeyDown(sender As Object, e As KeyEventArgs)
    Dim Element As GridSpinEditorElement = DirectCast(sender, GridSpinEditorElement)
    Select Case e.KeyData
        Case Keys.Up
            RemoveHandler Element.KeyDown, AddressOf element_KeyDown
            rgvFactor.GridNavigator.SelectPreviousRow(1)
        Case Keys.Down
            RemoveHandler Element.KeyDown, AddressOf element_KeyDown
            rgvFactor.GridNavigator.SelectNextRow(1)
        Case Keys.Enter
            RemoveHandler Element.KeyDown, AddressOf element_KeyDown
            rgvFactor.GridNavigator.SelectNextRow(1)
            RemoveHandler Element.KeyDown, AddressOf element_KeyDown
    End Select
End Sub
0
Stefan
Telerik team
answered on 29 Jan 2015, 07:45 AM
Here is an alternative as well:
Private Sub rgvFactor_CellEditorInitialized(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles rgvFactor.CellEditorInitialized
    Select Case e.ActiveEditor.GetType
        Case GetType(GridSpinEditor)
            Dim GseEditor As GridSpinEditor = TryCast(e.ActiveEditor, GridSpinEditor)
            If Not GseEditor Is Nothing Then
                Dim element As GridSpinEditorElement = TryCast(GseEditor.EditorElement, GridSpinEditorElement)
                element.InterceptArrowKeys = False
                       '
Cell editor initialized is fired every time the grid opens up an editor, so to avoid multiple subscriptions, we should first unsubscribe from previous subscriptions and the subscribe to the current editor
                RemoveHandler element.KeyDown, AddressOf element_KeyDown
                AddHandler element.KeyDown, AddressOf element_KeyDown
            End If
    End Select
End Sub
  
Private Sub element_KeyDown(sender As Object, e As KeyEventArgs)
    Dim Element As GridSpinEditorElement = DirectCast(sender, GridSpinEditorElement)
    Select Case e.KeyData
        Case Keys.Up
            rgvFactor.GridNavigator.SelectPreviousRow(1)
        Case Keys.Down
            rgvFactor.GridNavigator.SelectNextRow(1)
        Case Keys.Enter
            rgvFactor.GridNavigator.SelectNextRow(1)
    End Select
End Sub


Regards,
Stefan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Fariba
Top achievements
Rank 1
answered on 10 Nov 2015, 07:37 AM

hi

I have problem with key down in radDock

raddock keydown event does not fired

I opened a form  in raddock and short key of form does not work

while by showing this form in another way like form.show()  (not in raddock) all short keys work .

 

fariba

0
Stefan
Telerik team
answered on 10 Nov 2015, 07:55 AM
Hi Fariba,

This thread concerns RadGridView, not RadDock control. May I please ask you to open up a new thread in the respective forum. In the thread, please provide description of the case, as I am unable to get a clear picture of the scenario from the provided information.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
AJing
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Mark
Top achievements
Rank 2
Fariba
Top achievements
Rank 1
Share this question
or