This question is locked. New answers and comments are not allowed.
I've been using dynamic objects bound to a RadGridView control. Yeah our business model here is quite weird. Anyway, they've been working fine and dandy... until I tried implementing a combobox column! *insert ominous sound here*
Here's how to reproduce the problem:
Define a LookupItem class as:
Create instances of this class and put them into a list called lookups that you will use later as an ItemsSource for a GridViewComboBoxColumn.
Afterwards, create a collection of dynamic objects using the ExpandoObject class which you will then put into a grid called "gridView".
Finally, we manually specify the columns for the grid. Don't forget to assign the lookups we created to the combobox column's ItemsSource.
If you try that, you will get a grid with two columns, one with a combobox that is not correctly bound, and one with normal text that is correctly bound to "Prop2".
And if you do not use dynamic classes, i.e. you specifically create "Prop1" and "Prop2" properties, you will see that the combobox column will be bound correctly to "Prop1".
Is this a limitation on the current control, or is there a possible workaround? Looking forward to the fun times ahead...
Here's how to reproduce the problem:
Define a LookupItem class as:
public
class
LookupItem
{
public
object
Key {
get
;
set
; }
public
object
Value {
get
;
set
; }
}
Create instances of this class and put them into a list called lookups that you will use later as an ItemsSource for a GridViewComboBoxColumn.
var lookups =
new
ObservableCollection<LookupItem>();
lookups.Add(
new
LookupItem() { Key =
"1"
, Value =
"test1 - value"
});
lookups.Add(
new
LookupItem() { Key =
"2"
, Value =
"test2 - value"
});
Afterwards, create a collection of dynamic objects using the ExpandoObject class which you will then put into a grid called "gridView".
var list =
new
ObservableCollection<ExpandoObject>();
dynamic row =
new
ExpandoObject();
row.Prop1 =
"1"
;
row.Prop2 =
"foo"
;
list.Add(row);
row =
new
ExpandoObject();
row.Prop1 =
"2"
;
row.Prop2 =
"bar"
;
list.Add(row);
gridView.ItemsSource = list;
Finally, we manually specify the columns for the grid. Don't forget to assign the lookups we created to the combobox column's ItemsSource.
gridView.Columns.Clear();
var column1 =
new
GridViewComboBoxColumn();
column1.DisplayMemberPath =
"Value"
;
column1.SelectedValueMemberPath =
"Key"
;
column1.DataMemberBinding =
new
Binding(
"Prop1"
);
column1.UniqueName =
"Prop1"
;
column1.ItemsSource = lookups;
gridView.Columns.Add(column1);
var column2 =
new
GridViewDataColumn();
column2.DataMemberBinding =
new
Binding(
"Prop2"
);
column2.UniqueName =
"Prop2"
;
gridView.Columns.Add(column2);
If you try that, you will get a grid with two columns, one with a combobox that is not correctly bound, and one with normal text that is correctly bound to "Prop2".
And if you do not use dynamic classes, i.e. you specifically create "Prop1" and "Prop2" properties, you will see that the combobox column will be bound correctly to "Prop1".
Is this a limitation on the current control, or is there a possible workaround? Looking forward to the fun times ahead...