Unplanned
Last Updated: 15 Aug 2017 10:08 by ADMIN
ADMIN
Stefan
Created on: 01 Mar 2016 10:53
Category: GridView
Type: Feature Request
0
ADD. RadGridView - add new selection mode allowing selecting rows with Control and Up/Down arrow keys
The selection mode should be as in Windows Explorer - when Control is pressed, one should be able to move the current row with the up/down arrow keys and when Space is pressed, the current row should be selected/deselected. 

This implementation can be used for the time being:
  public partial class Form1 : RadForm
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            AddGridSimpleUnbound();
            radGridView1.MultiSelect = true;

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

            radGridView1.GridViewElement.Navigator = new MyNavigator();
        }

        class MyNavigator : BaseGridNavigator
        {
            protected override bool DoMultiSelect(GridViewRowInfo oldRow, GridViewColumn oldColumn, GridViewRowInfo row, GridViewColumn column)
            {
                if (!this.IsShiftButtonPressed && this.IsControlButtonPressed && !this.IsMouseSelection)
                {
                    return true;
                }

                return base.DoMultiSelect(oldRow, oldColumn, row, column);
            }
        }

        class MyRowBehavior : GridDataRowBehavior
        {
            bool kbdSelection = false;
            public override bool ProcessKeyPress(KeyPressEventArgs keys)
            {
                if (kbdSelection)
                {
                    kbdSelection = false;
                    return true;
                }
                return base.ProcessKeyPress(keys);
            }
            public override bool ProcessKey(KeyEventArgs keys)
            {
                if (keys.KeyCode == Keys.Space && this.GridControl.MultiSelect && keys.Control)
                {
                    this.GridControl.CurrentRow.IsSelected ^= true;
                    kbdSelection = true;
                    return false;
                }
                else
                {
                    return base.ProcessKey(keys);
                }
            }
        }
}
0 comments