This question is locked. New answers and comments are not allowed.
Hello Telerik,
I think I've found an issue with the RadGridView SelectedItem.
When I bind it to my ViewModel, and set my property, the view never select the row.
Here is a little example to illustrate this :
My ViewModel
My View :
If I want to select the right row, I need to do something like this :
Greetings,
Laurent
I think I've found an issue with the RadGridView SelectedItem.
When I bind it to my ViewModel, and set my property, the view never select the row.
Here is a little example to illustrate this :
My ViewModel
public
class
VisitorsViewModel : NotificationObject {
VisitorViewModel _chuck =
new
VisitorViewModel() { ID = 2, FirstName =
"Chuck"
, LastName =
"Noris"
};
VisitorViewModel _selectedItem;
public
VisitorViewModel SelectedItem {
get
{
return
_selectedItem; }
set
{
_selectedItem = value;
RaisePropertyChanged(
"SelectedItem"
);
}
}
public
ObservableCollection<VisitorViewModel> Items {
get
;
set
; }
public
VisitorsViewModel() {
Items =
new
ObservableCollection<VisitorViewModel>(
new
VisitorViewModel [] {
new
VisitorViewModel() { ID = 1, FirstName =
"Bruce"
, LastName =
"Lee"
},
_chuck,
new
VisitorViewModel() { ID = 3, FirstName =
"Steven"
, LastName =
"Seagal"
},
new
VisitorViewModel() { ID = 4, FirstName =
"Jean-Claude"
, LastName =
"Van Damme"
}
} );
SelectedItem = _chuck;
}
}
My View :
<
UserControl
x:Class
=
"GridViewSelectedItemTest.MainPage"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
mc:Ignorable
=
"d"
d:DesignWidth
=
"640"
d:DesignHeight
=
"480"
>
<
Grid
x:Name
=
"LayoutRoot"
>
<
telerik:RadGridView
x:Name
=
"gvVisitor"
ItemsSource
=
"{Binding Items}"
SelectionMode
=
"Single"
SelectionUnit
=
"FullRow"
SelectedItem
=
"{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
/>
</
Grid
>
</
UserControl
>
If I want to select the right row, I need to do something like this :
public
MainPage() {
InitializeComponent();
this
.DataContext =
new
VisitorsViewModel();
this
.Loaded +=
new
System.Windows.RoutedEventHandler( MainPage_Loaded );
}
void
MainPage_Loaded(
object
sender, System.Windows.RoutedEventArgs e ) {
gvVisitor.SelectedItems.Add( (DataContext
as
VisitorsViewModel).SelectedItem );
}
Greetings,
Laurent