WPF DatagridComboBoxColumn - puzzler
-
Kind of a newbie question. In my XAML I have these 2 lines
The first one WILL NOT display the value but the second one will. I created the second line to test my sanity [and the binding]. In the viewmodel I've exposed a
List
that I had initially bound to the combobox column's ItemsSource. However, when the column failed to display any data I removed it to see if that made a difference. With the List bound to the ItemsSource there was no value for the bound ExpenseCategory property and nothing in the list of values. That XAML was simply:
So...what am I missing here? Why won't the combobox column display my data?
-
Kind of a newbie question. In my XAML I have these 2 lines
The first one WILL NOT display the value but the second one will. I created the second line to test my sanity [and the binding]. In the viewmodel I've exposed a
List
that I had initially bound to the combobox column's ItemsSource. However, when the column failed to display any data I removed it to see if that made a difference. With the List bound to the ItemsSource there was no value for the bound ExpenseCategory property and nothing in the list of values. That XAML was simply:
So...what am I missing here? Why won't the combobox column display my data?
FWIW - and I have no idea if this is even close to an optimal approach - I found this solution in an old article by Julie Lerman http://msdn.microsoft.com/en-us/magazine/gg983481.aspx[^]
In her article she explains that the Grid FocusManager is used to manage the events when a new row is created and the user's first click is in the combobox. This approach seems to work OK, but it is far from straightforward and I hope that somebody here has a better solution that would allow the DataGridComboboxColumn to work for me.
-
FWIW - and I have no idea if this is even close to an optimal approach - I found this solution in an old article by Julie Lerman http://msdn.microsoft.com/en-us/magazine/gg983481.aspx[^]
In her article she explains that the Grid FocusManager is used to manage the events when a new row is created and the user's first click is in the combobox. This approach seems to work OK, but it is far from straightforward and I hope that somebody here has a better solution that would allow the DataGridComboboxColumn to work for me.
How about combining the two approaches? Since you've already managed to get the viewmodel into a static resource, something like this should work:
<DataGridComboBoxColumn
SelectedItemBinding="{Binding ExpenseCategory}"
ItemsSource="{Binding ExpTypes, Source={StaticResource vm}}"
Header="Category"
/>
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
How about combining the two approaches? Since you've already managed to get the viewmodel into a static resource, something like this should work:
<DataGridComboBoxColumn
SelectedItemBinding="{Binding ExpenseCategory}"
ItemsSource="{Binding ExpTypes, Source={StaticResource vm}}"
Header="Category"
/>
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thanks for the reply. I've been crawling my way towards that solution by incrementally melding some of the elements of Julie Lerman's approach with a DataGridComboBoxColumn, just hadn't gotten all the way to the one you've suggested. However, I've just tried your code and it works. Much more concise. Probably should have mentioned in the original question that I'd taken the [non-working] syntax directly from MSDN's latest example for combo box columns, and that had me flummoxed.