0

I Have a Combobox in a RowdetailsTemplate in a Datagrid. If i switch the columns then automatic change the value in the Datagridcolumn with the before selected Value. The Value in Datagrid column should only change if the value in the Combobox are changed

public class BMFill
{
    public BMFill()
    {
         colCBArt.Add(new CBArt { Name = "test" , Nr = 0 });
        colCBArt.Add(new CBArt { Name = "hallo", Nr = 1 });
        colCBArt.Add(new CBArt { Name = "welt", Nr = 2 });
        colCBArt.Add(new CBArt { Name = "blubb", Nr = 3 });
        colCBArt.Add(new CBArt { Name = "lalalala", Nr = 4 });

    }
    List<CBArt> colCBArt = new List<CBArt>();
    CollectionViewSource cvsCBArt = null;


    public ICollectionView ViewCBArt
    {
        get
        {
            if (cvsCBArt == null) cvsCBArt = new CollectionViewSource() { Source = colCBArt };
            return cvsCBArt.View;
        }
    }


    public class CBArt
    {
        public string Name { get; set; }
        public int Nr { get; set; }
    }
}

<Window.Resources>
    <local:BMFill x:Key="vm"/>
</Window.Resources>
<DataGrid x:Name="dg">
    <DataGrid.RowDetailsTemplate>
        <DataTemplate>
            <ComboBox Margin="10,10,10,10" Grid.Column="1" Grid.Row="1"
                                  SelectedValuePath="Nr"
                                  SelectedValue="{Binding NrDG,UpdateSourceTrigger=PropertyChanged}"
                                  DisplayMemberPath="Name" 
                                  ItemsSource="{Binding Source={StaticResource vm}, Path=ViewCBArt}"
                                  />
        </DataTemplate>
    </DataGrid.RowDetailsTemplate>
</DataGrid>

i hope can understand my problem and can me help =)

2 Answers2

0

You can try to add event handlers for DropDownOpened and DropDownClosed events, raise a flag while the dropdown is opened, and check if this flag is not raised while you change the value in the Datagridcolumn.

XAML:

        <ComboBox Margin="10,10,10,10" Grid.Column="1" Grid.Row="1"
                              SelectedValuePath="Nr"
                              SelectedValue="{Binding NrDG,UpdateSourceTrigger=PropertyChanged}"
                              DisplayMemberPath="Name" 
                              ItemsSource="{Binding Source={StaticResource vm}, Path=ViewCBArt}"
                              DropDownOpened="OnDropDownOpened" DropDownClosed="OnDropDownClosed"
                              />

C#:

    private bool _comboxBoxIsOpened = false;
    private void OnDropDownOpened(object sender, EventArgs e)
    {
        _comboxBoxIsOpened = true;
    }

    private void OnDropDownClosed(object sender, EventArgs e)
    {
        _comboxBoxIsOpened = false;
    }
0
SelectedValuePath="Nr"
                                  SelectedValue="{Binding NrDG,UpdateSourceTrigger=PropertyChanged}"
                                  DisplayMemberPath="Name" 
                                  ItemsSource="{Binding Source={StaticResource vm}, Path=ViewCBArt}"
                                  IsSynchronizedWithCurrentItem="False"

this Solution work by me