This is a migrated thread and some comments may be shown as answers.
On Enter key move to next row and skip group header focus
6 Answers 20 Views
This is a migrated thread and some comments may be shown as answers.
Tomas
Top achievements
Rank 1
Veteran
Tomas asked on 23 Jul 2020, 03:00 PM

Good afternoon,

I would like to change grid cursor movement behavior when pressing Enter key in the grid with grouped records. I need to move cursor only through the column cells without focusing a group header.  Is it doable?

My grid settings are:

radGridView1.MasterTemplate.AutoExpandGroups = true;
radGridView1.EnterKeyMode = RadGridViewEnterKeyMode.EnterMovesToNextRow;

6 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Jul 2020, 04:46 AM

Hello, Tomas,

RadGridView manages user mouse and keyboard input over its rows by GridRowBehavior. Depending on the row type, RadGridView introduces different behaviors: https://docs.telerik.com/devtools/winforms/controls/gridview/rows/row-behaviors 

Thus, you can create a derivative of the respective row behavior that is needed in your scenario and override the respective method that handles the Enter key and execute the desired action, e.g. override the ProcessEnterKey method.

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

0
Tomas
Top achievements
Rank 1
Veteran
answered on 24 Jul 2020, 12:43 PM

Hello, Dess,

many thanks for the advice. I was successfull. The solution is not very nice, but it works as expected. If you see any issue with this solution, please notify me.

I registered my CustomGridRowBehavior() right after grid initialization:

BaseGridBehavior gridBehavior = rgvResults.GridBehavior as BaseGridBehavior;
gridBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
gridBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new CustomGridRowBehavior());

 

Then I prepared the implementation of derived class:

class CustomGridRowBehavior : GridDataRowBehavior
{
    protected override bool ProcessEnterKey(KeyEventArgs keys)
    {
        this.GridControl.GridNavigator.SelectNextRow(1);
        if (this.GridControl.CurrentRow.RowElementType.Name == "GridGroupHeaderRowElement")
        {
            this.GridControl.GridNavigator.SelectNextRow(1);
        }
        return base.ProcessF2Key(keys);
    }
}
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Jul 2020, 01:00 PM

Hi, Tomas,

I am glad that you have implemented an appropriate row behavior for your scenario. I have reviewed the provided code snippet and it seems good to me.

Just a small suggestion, instead of checking the name of the RowElementType, it is OK to check the type of the CurrentRow itself.

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

0
Tomas
Top achievements
Rank 1
Veteran
answered on 24 Jul 2020, 01:27 PM

Hi, Dess,

to be honest I did not figure out how to get type of CurrentRow and do the comparison to check if it is GridGroupHeaderRowElement. If you have spare time, could you post a code snippet how to beat this? It is not important, just for study purposes.

Have a great day,

Tomas

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Jul 2020, 11:58 AM
Hello, Tomas, 

Firstly, I would like to note that for GridViewGroupRowInfos, RadGridView offers a specific row behavior for handling the mouse/keyboard input: GridGroupRowBehavior. If you want to handle pressing Enter key when the group row is current, it is more appropriate to use it:
        public RadForm1()
        {
            InitializeComponent();

            BaseGridBehavior gridBehavior = this.radGridView1.GridBehavior as BaseGridBehavior;
            gridBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
            gridBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new CustomGridRowBehavior());

            gridBehavior.UnregisterBehavior(typeof(GridViewGroupRowInfo));
            gridBehavior.RegisterBehavior(typeof(GridViewGroupRowInfo), new CustomGridGroupRowBehavior());
        }

        public class CustomGridGroupRowBehavior : GridGroupRowBehavior
        {
            protected override bool ProcessEnterKey(KeyEventArgs keys)
            {

                return base.ProcessEnterKey(keys);
            }
        }

You can plug into the above code and execute the desired logic.

As to the question about checking the CurrentRow's type, please have a look at this code snippet:

                if (this.GridControl.CurrentRow is GridViewGroupRowInfo)
                {

                }

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

0
Tomas
Top achievements
Rank 1
Veteran
answered on 03 Aug 2020, 07:17 AM
Hi Dess, that is brilliant. Many thanks.
Asked by
Tomas
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Tomas
Top achievements
Rank 1
Veteran
Share this question
or