Setting CurrentRow clears the SelectedCells collection

6 posts, 0 answers
  1. Steve
    Steve avatar
    43 posts
    Member since:
    May 2014

    Posted 19 Feb Link to this post

    I am trying to implement an Excel-like enter key behavior where pressing enter moves to the next cell only within the selected cells. I am handling KeyDown and everything works fine using Grid.CurrentColumn to move the CurrentCell between columns. However as soon as my selection is more than one row and I need to wrap to the next row, setting Grid.CurrentColumn kills the SelectedCells collection. I tried every manner of selecting a current cell that I could find, but nothing helps. Most are worse. Using GridNavigator kills the selection for any move, and setting the IsCurrent property of the row kills the selection even if the row hasn't changed.

     

    All of the documentation I can find explicitly states that the current cell and the selected cells are supposed to be independent. Am I missing something?

     

    I have MultiSelect on and SelectionMode = CellSelect, and I am using VirtualMode for the data.

  2. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 22 Feb Link to this post

    Hello Steve,

    Thank you for writing.

    RadGridView manages user mouse and keyboard input over its rows by GridRowBehavior. Depending on the row type, RadGridView introduces different behaviors. Thus, you can override the ProcessEnterKey of the row behavior and perform the desired logic. Additional information for implementing custom row behaviors is available at the following help article: http://docs.telerik.com/devtools/winforms/gridview/rows/row-behaviors

    Note that RadGridView is supposed to keep the multiple selection when handling the mouse and keyboard input by holding the Shift key. If you need to keep the selection after processing the Enter key, you can store the selected cells and restore them after manipulating the current row/column. The following help article demonstrates how to select programmatically cells/rows: http://docs.telerik.com/devtools/winforms/gridview/selection/selecting-rows-and-cells-programmatically

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Steve
    Steve avatar
    43 posts
    Member since:
    May 2014

    Posted 22 Feb in reply to Dess Link to this post

    It doesn't really answer my question as to why the behavior is inconsistent between setting the current row and setting the current column. If the current cell is independent of the selection, then neither should clear the selection. If it is not independent, they should both clear the selection. As it is right now, it seems like a bug.
  5. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 25 Feb Link to this post

    Hello Steve,

    Thank you for writing back. 

    When you change the current column, the current row remains the same. Thus, when you have GridViewSelectionMode.CellSelect, you do not perform selecting a new cell. However, when you change the CurrentRow, the cell selection is changed. This is desired behavior. If you need to skip clearing the SelectedCells when setting the CurrentRow and while the Control key is not pressed, you can use a custom BaseGridNavigator and override the Select method to control whether the selection will be cleared:  
    public class CustomBaseGridNavigator : BaseGridNavigator
    {
        public override bool Select(GridViewRowInfo row, GridViewColumn column)
        {
            if (this.GridViewElement.Tag=="Skip")
            {
                return false;
            }
             
            return base.Select(row, column);
        }
    }

    public Form1()
    {
        InitializeComponent();
        this.radGridView1.MultiSelect = true;
        this.radGridView1.SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.CellSelect;
        this.radGridView1.GridViewElement.Navigator = new CustomBaseGridNavigator();
    }
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        this.radGridView1.CurrentColumn = this.radGridView1.Columns.Last();
    }
     
    private void radButton2_Click(object sender, EventArgs e)
    {
        this.radGridView1.GridViewElement.Tag = "Skip";
        this.radGridView1.CurrentRow = this.radGridView1.Rows.First();
        this.radGridView1.GridViewElement.Tag = null;
    }

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    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
  6. Steve
    Steve avatar
    43 posts
    Member since:
    May 2014

    Posted 08 Mar in reply to Dess Link to this post

    Sorry I do not agree "This is desired behavior"
  7. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 09 Mar Link to this post

    Hello Steve,

    Thank you for writing back. 

    I have discussed this case with the team and we decided to log it in our feedback portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - feedback item.

    I have also updated your Telerik points.

    Feel free to use the suggested solution to keep the selection.

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
     
Back to Top
UI for WinForms is Visual Studio 2017 Ready