I have a ViewModel that exposes a collection of items to be displayed in a grid. It also exposes a list of options for one the the properties (grid columns)
I tried to use a Combobox column - setting the items source to the list of choices, and setting the DisplayMemberPath and SelectedValueMemberPath appropriately.
It works... kinda. The problem is, the column doesn't show the selected values until you click on any cell in the column. If you click on any cell, then all cells in the column show the correct text. If you click on a cell in a different column, the values all disappear. Even weirder - if you sort the column, it completely breaks, and the comboboxes don't even have items to select. (their items source becomes null)
Here is some simplified code. What am I doing wrong?
I tried to use a Combobox column - setting the items source to the list of choices, and setting the DisplayMemberPath and SelectedValueMemberPath appropriately.
It works... kinda. The problem is, the column doesn't show the selected values until you click on any cell in the column. If you click on any cell, then all cells in the column show the correct text. If you click on a cell in a different column, the values all disappear. Even weirder - if you sort the column, it completely breaks, and the comboboxes don't even have items to select. (their items source becomes null)
Here is some simplified code. What am I doing wrong?
<
Grid
x:Name
=
"LayoutRoot"
Background
=
"White"
>
<
telerik:RadGridView
AutoGenerateColumns
=
"False"
ItemsSource
=
"{Binding Items}"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewComboBoxColumn
SelectedValueMemberPath
=
"ID"
DisplayMemberPath
=
"Name"
ItemsSource
=
"{Binding List}"
DataMemberBinding
=
"{Binding ListID}"
>
</
telerik:GridViewComboBoxColumn
>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
</
Grid
>
public
class
ViewModel
{
public
List<ListItem> List {
get
;
private
set
; }
public
List<Item> Items {
get
;
private
set
; }
public
ViewModel()
{
List =
new
List<ListItem>();
List.Add(
new
ListItem() { ID = 1, Name =
"Item 1"
});
List.Add(
new
ListItem() { ID = 2, Name =
"Item 2"
});
List.Add(
new
ListItem() { ID = 3, Name =
"Item 3"
});
Items =
new
List<Item>();
Items.Add(
new
Item() { ListID = 1 });
Items.Add(
new
Item() { ListID = 1 });
Items.Add(
new
Item() { ListID = 2 });
}
}
public
class
Item
{
public
int
ListID {
get
;
set
; }
}
public
class
ListItem
{
public
int
ID {
get
;
set
; }
public
string
Name {
get
;
set
; }
}
void
MainPage_Loaded(
object
sender, RoutedEventArgs e)
{
this
.DataContext =
new
ViewModel();
}