GridViewDecimalColumn - up/down arrow keys move between rows

5 posts, 1 answers
  1. Grand River Rubber
    Grand River Rubber avatar
    6 posts
    Member since:
    Oct 2012

    Posted 12 Nov 2018 Link to this post

    I have a RadGridView with a GridViewDecimalColumn. I want to allow the user to move up and down to other rows using the up/down arrow keys, but it changes the value instead. This occurs even if I set ShowUpDownButtons to false.

    I found an old example on the forum that explains how to change this behavior here: https://www.telerik.com/forums/gridviewdecimalcolumn-up-down-key. However when I try the code there, I can't get it to work. GridSpinEditorElement is not found. I have the Telerik.WinControls and Telerik.WinControls.UI namespaces included.

    I looked up GridSpinEditorElement, to see if I needed a different namespace, and it seems it's no longer available. I'm referencing this page:

    https://docs.telerik.com/devtools/winforms/api/html/t_telerik_wincontrols_ui_gridspineditorelement.htm

    It says it's obsolete and shows version 2018.1.220.40. I'm on version 2018.3.911.40.

    How can I implement this code now without GridSpinEditorElement?

    Thanks

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2841 posts

    Posted 13 Nov 2018 Link to this post

    Hi Scott,

    You need to use the RadSpinEditorElement class instead. Otherwise, the code is valid and will work for this case.

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Grand River Rubber
    Grand River Rubber avatar
    6 posts
    Member since:
    Oct 2012

    Posted 13 Nov 2018 Link to this post

    Thank you Dimitar, that worked! I also modified the element_KeyDown method so it gets the RadGridView from sender, so only one handler is needed for multiple grids. I'm including the code below for anyone else who stumbles across this thread.

    private void radGridView_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        if (e.ActiveEditor is GridSpinEditor editor)
        {
            var element = editor.EditorElement as RadSpinEditorElement;
            element.InterceptArrowKeys = false;
            element.KeyDown -= new KeyEventHandler(element_KeyDown);
            element.KeyDown += new KeyEventHandler(element_KeyDown);
        }
    }
     
     
    private void element_KeyDown(object sender, KeyEventArgs e)
    {
        if (sender is RadSpinEditorElement element)
        {
            var gridView = element.ElementTree.Control as RadGridView;
             
            if (e.KeyData == Keys.Down)
            {
                gridView.GridNavigator.SelectNextRow(1);
            }
            else if (e.KeyData == Keys.Up)
            {
                gridView.GridNavigator.SelectPreviousRow(1);
            }
        }
    }
  4. Dimitar
    Admin
    Dimitar avatar
    2841 posts

    Posted 14 Nov 2018 Link to this post

    Hi Scott,

    Thanks for sharing your solution. 

    Do not hesitate to contact us if you have other questions.
     
    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. andi
    andi avatar
    18 posts
    Member since:
    Oct 2018

    Posted 14 Nov 2018 in reply to Dimitar Link to this post

    Hi Dimitar,

    This is Gridviewdecimalcolumn and I have iterated the ChildRows collection for each parent row and evaluating the sum programmatically.
        Private Sub IterateRows()
            For Each row As GridViewRowInfo In template.Rows
                MsgBox("Baris Header : " & row.Cells(5).Value)
                Dim hierarchyRow As GridViewHierarchyRowInfo = TryCast(row, GridViewHierarchyRowInfo)
                If hierarchyRow IsNot Nothing Then
                    IterateChildRows(hierarchyRow)
                End If
            Next
        End Sub

        Private Sub IterateChildRows(ByVal rowInfo As GridViewHierarchyRowInfo)
            Dim currentView As GridViewInfo = rowInfo.ActiveView
            Dim totalsum As Double

            totalsum = 0
            For Each view As GridViewInfo In rowInfo.Views
                rowInfo.ActiveView = view
                For Each row As GridViewRowInfo In rowInfo.ChildRows
                    'MsgBox("Baris Detail : " & row.Cells(13).Value)
                    totalsum = totalsum + row.Cells(13).Value
                Next
            Next
            'MsgBox(totalsum)
            rowInfo.ActiveView = currentView
        End Sub
    Now, how to assigned the obtained result to the respective parent cell's value ? Thanks

Back to Top