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

CurrentItem does not change

2 Answers 72 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dongzhi
Top achievements
Rank 1
Dongzhi asked on 07 Jan 2014, 08:01 PM

I'm evaluating telerik gridview for the project I'm working on.  I noticed the CurrentItem does not change when I change selections in the grid.  The setter on CurrentItem in the ViewModel only gets triggered at the very first time.  

Here's the definition of the Grid:
<telerik:RadGridView  Name="GroceryGrid"
                     ItemsSource="{Binding GroceryList}"
                     IsSynchronizedWithCurrentItem="True"
                     AutoGenerateColumns="False"
                     SelectionMode="Multiple"
                     CurrentItem="{Binding CurrentItem, Mode=TwoWay}"
                     SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                     ShowColumnFooters="True"
                     DockPanel.Dock="Top"
                  >

In the ViewModel:

private GroceryItem currentItem;
public GroceryItem CurrentItem
{
    get { return this.currentItem; }
 
    set
    {
        this.currentItem = value;
        base.RaisePropertyChangedEvent("CurrentItem");
    }
}

Please help.  Thanks!
Dongzhi


2 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 10 Jan 2014, 11:23 AM
Hello Dongzhi,

This would be the expected behaviour when SelectionMode is set to Multiple. The reason for this behaviour is that the selected rows are added to the collection SelectedItems. Only the first item in this collection is added to SelectedItem which is synchronized with CurrentItem.

In order to update the CurrentItem you will have to subscribe to the SelectionChanged event, during which you can check if there are elements in the properties AddedItems, RemovedItems. These properties are part of the SelectionChangeEventArgs. You should also set IsSynchronizedWithCurrentItem to False.


You can see the following snippet for example:
private void clubsGrid_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)
        {
            if (e.AddedItems.Count != 0)
            {
                this.clubsGrid.CurrentItem = e.AddedItems[0];
            }
            if (e.RemovedItems.Count != 0)
            {
                this.clubsGrid.CurrentItem = e.RemovedItems[0];
            }
        }


Regards,
Hristo
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Dongzhi
Top achievements
Rank 1
answered on 10 Jan 2014, 02:15 PM

It works like a charm.  Thank you so much!  :)
Tags
GridView
Asked by
Dongzhi
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Dongzhi
Top achievements
Rank 1
Share this question
or