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

Setting CurrentRow clears the SelectedCells collection

5 Answers 163 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 19 Feb 2016, 11:36 PM

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.

5 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 22 Feb 2016, 02:54 PM
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 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
0
Steve
Top achievements
Rank 1
answered on 22 Feb 2016, 04:51 PM
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.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Feb 2016, 09:10 AM
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
0
Steve
Top achievements
Rank 1
answered on 09 Mar 2016, 12:02 AM
Sorry I do not agree "This is desired behavior"
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 09 Mar 2016, 01:10 PM
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  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.
 
Tags
GridView
Asked by
Steve
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Steve
Top achievements
Rank 1
Share this question
or