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

RadGridView, ObservableCollection and currentitem

4 Answers 555 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Knut
Top achievements
Rank 1
Knut asked on 27 Oct 2010, 09:07 AM
Hi
I'm trying to replace my wpf listview with radgridview, but the selecteditem binding to the observablecollection does not work.

<ListView Name="lboRoles" Grid.Row="1" Grid.Column="0" ItemsSource="{Binding}" Grid.ColumnSpan="1" IsSynchronizedWithCurrentItem="True"  SelectionMode="Single" >
     <ListView.View>
         <GridView>
             <GridViewColumn Header="Name" Width="200"  DisplayMemberBinding="{Binding Path=Name}"/>
             <GridViewColumn Header="Description" Width="200"  DisplayMemberBinding="{Binding Path=Description}"/>
         </GridView>
     </ListView.View>
 </ListView>
 <mytelerik:RadGridView x:Name="gvRoles" ItemsSource="{Binding}" SelectionMode="Single" IsReadOnly="True" 
                        Grid.Column="0" Grid.Row="0" IsSynchronizedWithCurrentItem="True" AutoGenerateColumns="False" 
                        ShowGroupPanel="False" CanUserFreezeColumns="False" ShowColumnFooters="False">
     <mytelerik:RadGridView.Columns>
         <mytelerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}">
         </mytelerik:GridViewDataColumn>
         <mytelerik:GridViewDataColumn Header="Description" DataMemberBinding="{Binding Description}">
         </mytelerik:GridViewDataColumn>
     </mytelerik:RadGridView.Columns>
 </mytelerik:RadGridView>


When selecting a row in the listview, the observablecollection currentrow is changed, but not when selecting a row in the radgridview.
Is there a different way to do this with radgridview? Do I need a binding to selecteditem?

Knut

4 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 02 Nov 2010, 04:10 PM

Hi Knut,

I am not sure if I understand the question correctly. Where is the current item defined? The ObservableCollection class does not expose current item property. Could you please elaborate on the issue.



Greetings,
Milan
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Marius
Top achievements
Rank 1
answered on 17 Dec 2010, 07:28 AM
This does not work because the RadGridView does not "respect the rules of binding". When you bind a collection to an ItemsSource, the target control should use the default CollectionView obtained through the CollectionViewSource.GetDefaultView(..), this way you get currency management for free. The ListView does the aforementioned, but the RadGridView does not. You can workaround this issue by doing one of the following:

1) Create a CollectionViewSource in the resource-section and bind it to the collection which you intend to bind to the grid, then bind your RadGridView to the CollectionViewSource. This however has the side-effect that you lose some IDataErrorInfo support since your binding to a ICollectionView instead of the actual collection.

2) Manually listen  to SelectedItemChanged on your grid and the default view CurrentItemChanged, sync them in code-behind. (use CollectionView.MoveCurrentItemTo() and similar on the grid.

I really hope this will be fixed soon because it was reported over a year ago.
0
StackOverflowed
Top achievements
Rank 1
answered on 22 Mar 2011, 09:11 PM
I agree. I see strange grid behavior where the current cell and selected cell/row go out of sync constantly. It's become extremely annoying for our users and the latest releases don't fix it.

Is there a way to keep the current cell and selected cells in sync?
0
Milan
Telerik team
answered on 28 Mar 2011, 05:38 PM

Hi StackOverflowed,

The selected cell/row is not kept in sync with current cell by design. If you would like to sync selected cell/row with the current cell you could use the following workaround.

 

public MainWindow()
{
    InitializeComponent();  
  
    this.clubsGrid.CurrentCellChanged+=new System.EventHandler<GridViewCurrentCellChangedEventArgs>(clubsGrid_CurrentCellChanged);
}
  
private void clubsGrid_CurrentCellChanged(object sender, GridViewCurrentCellChangedEventArgs e)
{
    e.NewCell.ParentRow.IsSelected = true;
}



Regards,
Milan
the Telerik team
Tags
GridView
Asked by
Knut
Top achievements
Rank 1
Answers by
Milan
Telerik team
Marius
Top achievements
Rank 1
StackOverflowed
Top achievements
Rank 1
Share this question
or