2012-11-01 67 views
0

我使用XAML在Datagrid中實現了DataGridComboBoxColumn。我可以以編程方式訪問comboboxColumn1,但如何在值更改時獲取所選項目?獲取Datagrid中的ComboBoxColumn的選定值(WPF)

<DataGrid x:Name="dgData" AutoGenerateColumns="False" Margin="131,93,13,101" Grid.Column="1" SelectionChanged="dgData_SelectionChanged"> 
     <DataGrid.Columns> 

      <DataGridComboBoxColumn Header="Subject" x:Name="comboboxColumn1"/> 

     </DataGrid.Columns> 
</DataGrid> 

回答

0

嘗試這種方式

<DataGridComboBoxColumn Header="Life Area" SelectedItemBinding="{Binding YourSelectedItem}"> 
    <DataGridComboBoxColumn.ElementStyle> 
     <Style TargetType="ComboBox"> 
      <Setter Property="ItemsSource" Value="{Binding YourItemSource}"/> 
      <Setter Property="IsReadOnly" Value="True"/> 
     </Style> 
    </DataGridComboBoxColumn.ElementStyle> 
    <DataGridComboBoxColumn.EditingElementStyle> 
     <Style TargetType="ComboBox"> 
      <Setter Property="ItemsSource" Value="{Binding YourItemSource}"/> 
     </Style> 
    </DataGridComboBoxColumn.EditingElementStyle> 
</DataGridComboBoxColumn> 
+0

我想在代碼中的組合框的值,而不是通過XAML。 – Omid