Search code examples
c#wpfdatagridcombobox

WPF datagrid combobox column: how to manage event of selection changed?


I have a datagrid, with a combobox column

<DataGridComboBoxColumn x:Name="DataGridComboBoxColumnBracketType" Width="70" Header="Tipo di staffa" SelectedValueBinding="{Binding type, UpdateSourceTrigger=PropertyChanged}">                    
            </DataGridComboBoxColumn>

I want an event that is fired only when the user changes the value into the combobox. How can I resolve this?


Solution

  • I found a solution to this on CodePlex. Here it is, with some modifications:

    <DataGridComboBoxColumn x:Name="Whatever">                    
         <DataGridComboBoxColumn.EditingElementStyle>
              <Style TargetType="{x:Type ComboBox}">
                   <EventSetter Event="SelectionChanged" Handler="SomeSelectionChanged" />
              </Style>
         </DataGridComboBoxColumn.EditingElementStyle>           
    </DataGridComboBoxColumn>
    

    and in the code-behind:

    private void SomeSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
         var comboBox = sender as ComboBox;
         var selectedItem = this.GridName.CurrentItem;
    
    }