Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Databinding with DataGridComboBoxColumn

This is what I want:

  • There is a combo-box column bound to the ApplicationKey property of ClassA
  • The combo-box is populated with ApplicationTokens from a static function all.
  • An ApplicationToken has a ApplicationName and ApplicationKey property
  • When an item is selected in the drop-down, the ClassA.ApplicationKey property is set to the ApplicationToken.ApplicationKey on the selected item.

This is my current code, which populates the combobox but doesn't update ClassA.ApplicationKey.

<DataGridComboBoxColumn 
    Header="Application" 
    SelectedItemBinding="{Binding ApplicationKey, Converter={gui:DebugConverter}}" 
    SelectedValuePath="ApplicationKey" 
    DisplayMemberPath="ApplicationName" 
    ItemsSource="{Binding Source={x:Static app:ApplicationLookup.GetAllOrNone}}"/>
like image 353
Jonathan Allen Avatar asked Jul 26 '10 18:07

Jonathan Allen


1 Answers

Use SelectedValueBinding instead of SelectedItemBinding when using SelectedValuePath.

Working example

<DataGridComboBoxColumn 
    Header="Application" 
    SelectedValueBinding="{Binding ApplicationKey}"
    SelectedValuePath="ApplicationKey" 
    DisplayMemberPath="ApplicationName" 
    ItemsSource="{Binding Source={x:Static app:ApplicationLookup.GetAllOrNone}}"/>
like image 169
Wallstreet Programmer Avatar answered Nov 05 '22 15:11

Wallstreet Programmer