GridViewDecimalColumn Up& down key

11 posts, 0 answers
  1. AJing
    AJing avatar
    19 posts
    Member since:
    Jun 2011

    Posted 12 Dec 2011 Link to this post

    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
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 16 Dec 2011 Link to this post

    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.

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mark
    Mark avatar
    18 posts
    Member since:
    Nov 2011

    Posted 27 Jan 2015 in reply to Stefan Link to this post

    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. 


  5. Mark
    Mark avatar
    18 posts
    Member since:
    Nov 2011

    Posted 27 Jan 2015 in reply to Mark Link to this post

    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
  6. Mark
    Mark avatar
    18 posts
    Member since:
    Nov 2011

    Posted 27 Jan 2015 in reply to Stefan Link to this post

    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?
  7. Mark
    Mark avatar
    18 posts
    Member since:
    Nov 2011

    Posted 27 Jan 2015 in reply to Stefan Link to this post

    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
  8. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 28 Jan 2015 Link to this post

    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.

     
  9. Mark
    Mark avatar
    18 posts
    Member since:
    Nov 2011

    Posted 28 Jan 2015 in reply to Stefan Link to this post

    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
  10. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 29 Jan 2015 Link to this post

    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.

     
  11. fariba
    fariba avatar
    21 posts
    Member since:
    May 2014

    Posted 10 Nov 2015 Link to this post

    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

  12. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 10 Nov 2015 Link to this post

    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 detailed 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
Back to Top
UI for WinForms is Visual Studio 2017 Ready