问候,
我有一个DataGrid
带有复选框的列,允许用户选择行,列标题中有一个“全选”复选框,组标题中有一个“全选”复选框。
XAML:
<DataGrid CanUserAddRows="True" CanUserDeleteRows="True" Grid.ColumnSpan="2" Margin="7,4,8,41" Name="customerDataGrid" Grid.Row="3" ItemsSource="{Binding}" ColumnHeaderStyle="{Binding Source={StaticResource TabControlInnerBorder}}" DataContext="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=DataGrid, AncestorLevel=1}}">
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=City}" FontWeight="Bold" Padding="3"/>
</StackPanel>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander>
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Path=Name}" />
<TextBlock Text="{Binding Path=ItemCount}" />
<TextBlock Text="Emp(s)" />
<CheckBox Content="{Binding Path=Name}" ClickMode="Press" Checked="CheckBox_Checked" />
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
</DataGrid>
。CS
private ICollectionView defaultView1;
public main1_windows()
{
InitializeComponent();
List<Employ> empl = new List<Employ>();
empl = LoadData();
this.defaultView1 = CollectionViewSource.GetDefaultView(empl);
this.defaultView1.GroupDescriptions.Add(new PropertyGroupDescription ("dep"));
this.defaultView1.Filter = new Predicate<object>(Contains1);
}
public bool Contains1(object de)
{
Employ order = de as Employ;
//Return members whose Orders have not been filled
return (order.Name.ToString().Contains(textBox4.Text).Equals(true));
}
private List<Employ> LoadData()
{
List<Employ> employ = new List<Employ>();
employ.Add(new Employ()
{
ID = 2000,
Name = "moh",
DOB = new DateTime(1985, 5, 15),
dep="pro",
IsNew = false
});
employ.Add(new Employ()
{
ID = 3000,
Name = "jac",
DOB = new DateTime(1985, 5, 15),
dep="pro",
IsNew = false
});
employ.Add(new Employ()
{
ID = 4000,
Name = "ahmad",
DOB = new DateTime(1985, 5, 15),
dep="admin",
IsNew = false
});
return employ;
}
public class Employ
{
public int ID { get; set; }
public string Name { get; set; }
public DateTime DOB { get; set; }
public string dep { get; set; }
public bool IsNew { get; set; }
}
private void textBox4_TextChanged(object sender, TextChangedEventArgs e)
{
this.defaultView1.Filter = new Predicate<object>(Contains1);
}
private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
// I want when the apical true check box in the group all the rows in this group check box true value;
}
我如何选择组
Thanks 中的所有行。