I'm trying to use ItemsSourceBinding. The list is displayed but the selected item is not commited to binded property (see attached picture).
XAML:
ViewModel:
This sample is based on SL sample attached by Maya here: http://www.telerik.com/community/forums/silverlight/gridview/binding-from-radgridview-to-radcombobox.aspx
XAML:
<
telerik:RadGridView
Name
=
"playersGrid"
ItemsSource
=
"{Binding Players}"
AutoGenerateColumns
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Name}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Number}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Position}"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Country}"
IsReadOnlyBinding
=
"{Binding IsReadOnlyProperty}"
/>
<
telerik:GridViewComboBoxColumn
DataMemberBinding
=
"{Binding ClubID}"
SelectedValueMemberPath
=
"ID"
ItemsSourceBinding
=
"{Binding AvailableClubs}"
DisplayMemberPath
=
"Name"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
ViewModel:
/// <summary>
/// A football player.
/// </summary>
public
class
Player : INotifyPropertyChanged
{
public
event
PropertyChangedEventHandler PropertyChanged;
private
string
name;
private
int
number;
private
Position position;
private
string
country;
private
bool
isReadOnlyProperty;
public
bool
IsReadOnlyProperty
{
get
{
return
this
.isReadOnlyProperty; }
set
{
if
(value !=
this
.isReadOnlyProperty)
{
this
.isReadOnlyProperty = value;
this
.OnPropertyChanged(
"IsReadOnlyProperty"
);
}
}
}
private
int
clubID;
public
int
ClubID
{
get
{
return
this
.clubID; }
set
{
if
(value !=
this
.clubID)
{
this
.clubID = value;
this
.UpdateIsReadOnlyProperty(
this
.clubID);
this
.OnPropertyChanged(
"ClubID"
);
}
}
}
public
string
Name
{
get
{
return
this
.name; }
set
{
if
(value !=
this
.name)
{
this
.name = value;
this
.OnPropertyChanged(
"Name"
);
}
}
}
public
int
Number
{
get
{
return
this
.number; }
set
{
if
(value !=
this
.number)
{
this
.number = value;
this
.OnPropertyChanged(
"Number"
);
}
}
}
public
Position Position
{
get
{
return
this
.position; }
set
{
if
(value !=
this
.position)
{
this
.position = value;
this
.OnPropertyChanged(
"Position"
);
}
}
}
public
string
Country
{
get
{
return
this
.country; }
set
{
if
(value !=
this
.country)
{
this
.country = value;
this
.OnPropertyChanged(
"Country"
);
}
}
}
public
IEnumerable<Club> AvailableClubs
{
get
{
return
from c
in
Club.GetClubs()
where c.ID ==
this
.ClubID
select c;
}
}
public
Player()
{
}
public
Player(
string
name,
int
number, Position position,
string
country,
int
clubID,
bool
isReadOnlyProperty)
{
this
.name = name;
this
.number = number;
this
.position = position;
this
.country = country;
this
.clubID = clubID;
this
.isReadOnlyProperty = isReadOnlyProperty;
}
protected
virtual
void
OnPropertyChanged(PropertyChangedEventArgs args)
{
PropertyChangedEventHandler handler =
this
.PropertyChanged;
if
(handler !=
null
)
{
handler(
this
, args);
}
}
private
void
OnPropertyChanged(
string
propertyName)
{
this
.OnPropertyChanged(
new
PropertyChangedEventArgs(propertyName));
}
public
override
string
ToString()
{
return
this
.Name;
}
public
static
ObservableCollection<Player> GetPlayers()
{
return
new
ObservableCollection<Player>(Club.GetClubs().SelectMany(c => c.Players));
}
private
void
UpdateIsReadOnlyProperty(
int
clubID)
{
if
(clubID == 2 || clubID == 3)
{
this
.IsReadOnlyProperty =
true
;
}
else
{
this
.IsReadOnlyProperty =
false
;
}
}
}
This sample is based on SL sample attached by Maya here: http://www.telerik.com/community/forums/silverlight/gridview/binding-from-radgridview-to-radcombobox.aspx