내 DataGrid에 ComboBox가 DataGridTemplateColumn에 있고 SelectionChanged 이벤트에 반응하고 싶습니다. 내 XAML :ComboBox의 SelectionChanged는 DataGrid 요소가 그룹화 될 때 발생합니다.
<DataGrid ItemsSource="{Binding}" SelectionChanged="dataGrid1_SelectionChanged"
SelectionMode="Single" Name="dataGrid1" ...>
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander Name="exp" IsExpanded="True">
<Expander.Header>
<TextBlock Text="{Binding SelectedValue,
ElementName=groupCB}"/>
</Expander.Header>
<Expander.Content>
<ItemsPresenter/>
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
<DataGrid.Columns>
<DataGridTemplateColumn Header="status" ...>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Path=StatusL, RelativeSource={
RelativeSource Mode=FindAncestor, AncestorType={
x:Type Window}}}" SelectedItem="{Binding Status}"
Name="statusCB" SelectionChanged="StatusCB_SelectionChanged" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
...
</DataGrid.Columns>
</DataGrid>
그리고 콤보 상자의 인 selectionchanged - 방법 :
private void StatusCB_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
// do something
}
DataGrids를의 DataContext는 DataTable에의 CollectionView입니다. 새로운 행이 데이터 격자에 해당 행의 콤보 인 selectionchanged위한 메소드를 삽입
DataTable _record_data = new DataTable("records");
CollectionView _records_view = (CollectionView)CollectionViewSource.GetDefaultView(_record_data);
dataGrid1.DataContext = _records_view;
PropertyGroupDescription _group_description = new PropertyGroupDescription(groupCB.SelectedValue.ToString()); // groupCB is another ComboBox
_records_view.GroupDescriptions.Clear();
_records_view.GroupDescriptions.Add(_group_description);
호출된다 그룹에 데이터 격자 열은이 코드를 사용한다. ComboBox 행의 선택한 항목을 변경하면 DataGrid를 다시 그룹화하려고합니다. 그러나 regroup-method에 새 GroupDescription을 추가하면 각 행의 SelectionChanged 메서드가 호출됩니다. 이것은 무한 루프에서 끝납니다.
나는 내 문제를 설명 할 수 있기를 바랍니다.
덕분에 어떤 도움
try e.Handled = True .. in StatusCB_SelectionChanged – Vishal