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

GridViewDecimalColumn - up/down arrow keys move between rows

4 Answers 749 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Grand River Rubber
Top achievements
Rank 2
Grand River Rubber asked on 12 Nov 2018, 08:05 PM

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

4 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 13 Nov 2018, 09:31 AM
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.
0
Grand River Rubber
Top achievements
Rank 2
answered on 13 Nov 2018, 04:42 PM
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);
        }
    }
}
0
Dimitar
Telerik team
answered on 14 Nov 2018, 09:38 AM
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.
0
andi
Top achievements
Rank 1
answered on 15 Nov 2018, 02:03 AM

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

Tags
GridView
Asked by
Grand River Rubber
Top achievements
Rank 2
Answers by
Dimitar
Telerik team
Grand River Rubber
Top achievements
Rank 2
andi
Top achievements
Rank 1
Share this question
or