2017-04-25 6 views
0

データグリッド内のRowdetailsTemplateにコンボボックスがあります。私は列を切り替えると、前に選択した値でDatagridcolumnの値を自動的に変更します。 コンボボックスの値がRowDetailTemplateのComboboxが選択された列の前にすべて更新されます

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> 

を変更している場合はDataGrid列の値が唯一の私は私の問題を理解することができますし、私は=役立つことを願って変更する必要があります)

答えて

0
SelectedValuePath="Nr" 
            SelectedValue="{Binding NrDG,UpdateSourceTrigger=PropertyChanged}" 
            DisplayMemberPath="Name" 
            ItemsSource="{Binding Source={StaticResource vm}, Path=ViewCBArt}" 
            IsSynchronizedWithCurrentItem="False" 

0

あなたはDropDownOpenedのイベントハンドラを追加しようとすることができますし、 DropDownClosedイベント、ドロップダウンが開かれている間にフラグを立て、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

私の問題は、コンボボックスの値を変更した場合、私はDataGrid列を更新する必要がある私が、このソリューションの作品 –

+0

@ToniSchönbergerので、以前の値をOpenedに保存して、Closedで変更されているかどうかを確認できます(グローバルv ariable)。もしそうなら、Datagrid Columを更新する – ShugiShugi

関連する問題