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

Bug in RadGridView: CurrentCell not in sync with SelectedCells / SelectedRow

3 Answers 290 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Seba
Top achievements
Rank 1
Seba asked on 21 Nov 2011, 11:29 AM

Hi,

I have a experienced a lot af problems when using SelectionUnit FullRow. The CurrentCell property does not seem to be in sync all the time with the SelectedCells / SelectedRow properties. I have frequent cases where this happens but these are difficult to reproduce.
I have one case though were I could always reproduce this: when cancelling the selection in the SelectionChanging event. When doing so the CurrentCell is still set to another row and when clicking this same cell a second time there are no Selection events any more.

I use version 2011.2.920.40 of the Telerik WPF library.

A sample solution can be downloaded here.

Sébastien

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 23 Nov 2011, 10:46 AM
Hello Seba,

Thank you for the sample project.
 
Indeed the CurrentCell should not be syncronized with the SelectedRow /SelectedCells. You could move the CurrentCell (for example by using the keyboard navigation) without selecting its corresponding GridViewRow.

As to the problem that you have reproduced, this behaviour have been changed for the Q3 2011 release of the RadControls.
If you prefer not to upgrade, then I would suggest you the following workaround:

public MainWindow()
       {...
           this.RadGridView.CanUserSelect = false;
           this.AddHandler(FrameworkElement.MouseDownEvent, new System.Windows.Input.MouseButtonEventHandler(OnMouseDown), true);
       }
  
       private void OnMouseDown(object sender, MouseButtonEventArgs e)
       {
           var s = e.OriginalSource as FrameworkElement;
           var parentRow = s.ParentOfType<GridViewRow>();
           if (parentRow != null)
           {
           if (Keyboard.Modifiers == ModifierKeys.Control)
           {
               parentRow.IsSelected = false;
           }
           else
           {
               parentRow.IsSelected = true;
           }
    }
}


I hope that this is helpful.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Seba
Top achievements
Rank 1
answered on 23 Nov 2011, 02:00 PM
Hi,

First of all, many thanks for the quick reply. I tried your suggestion but the problem with that approach is that it breaks the keyboard navigation (up/down) for the selection of rows. I have found another workaround but it is not tested thoroughly. This is my solution (we subclass the RadGridView).

    public class DataGridView : RadGridView
    {
        public DataGridView()
        {
            CurrentCellChanged += DataGridViewCurrentCellChanged;
        }
 
        private void DataGridViewCurrentCellChanged(object sender, GridViewCurrentCellChangedEventArgs e)
        {
            //when canceling the Selection the CurrentCell(Info) is not in sync with the SelectedCells property
            //this is a work around for this bug
            if (SelectedCells != null && SelectedCells.Count > 0)
            {
                if (CurrentCellInfo != SelectedCells[0])
                    CurrentCellInfo = SelectedCells[0];
            }
            else if (CurrentCellInfo != null)
            {
                //The CurrentCell poperty has no setter but setting the CurrentColumn property to null
                //has the same effect.
                CurrentColumn = null;
            }  
        }
 
...

0
Dimitrina
Telerik team
answered on 25 Nov 2011, 11:02 AM
Hello Seba,

 I am not sure that your code snippet will work fine in some scenarios. I would recommend you to upgrade to the newest version of the RadControls. Then your requirement will work out of the box. Furthermore, the latest version has fixes and many improvements.

As to changing the behaviour in the current version, what I would suggest you is an addition to my previous solution. You could keep it and add these changes to the DataGridViewCurrentCellChanged event handler:

private void DataGridViewCurrentCellChanged(object sender, GridViewCurrentCellChangedEventArgs e)
       {
           this.RadGridView.SelectedItem = e.NewCell.DataContext;
       }


I hope that this helps.

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Seba
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Seba
Top achievements
Rank 1
Share this question
or