C# 选中列表框以更新网格
这是我的问题: 我有一个清单框,里面装满了学生。通过选中复选框选择学生时,我希望它显示在数据网格中。此外,如果学生未被检查,则应将其从数据网格中删除 我可以将我的集合绑定到检查表框,但当学生被选中时,它不会触发属性更改事件,我假设是因为更改的属性是它绑定到的集合的子级。因此,我也将更改的属性添加到集合中 下面是我一直在玩的一些代码 如有义务:C# 选中列表框以更新网格,c#,.net,wpf,C#,.net,Wpf,这是我的问题: 我有一个清单框,里面装满了学生。通过选中复选框选择学生时,我希望它显示在数据网格中。此外,如果学生未被检查,则应将其从数据网格中删除 我可以将我的集合绑定到检查表框,但当学生被选中时,它不会触发属性更改事件,我假设是因为更改的属性是它绑定到的集合的子级。因此,我也将更改的属性添加到集合中 下面是我一直在玩的一些代码 如有义务: public IEnumerable<SelectedStudent> ActiveStudents { get { return _
public IEnumerable<SelectedStudent> ActiveStudents
{
get { return _activeStudents; }
set
{
_activeStudents = value;
RaisePropertyChanged("ActiveStudents");
RaisePropertyChanged("GridDisplay");
}
}
public IEnumerable<SelectedStudent> GridDisplay
{
get
{
var aa = _activeStudents.Where(a => a.Select == true);
return aa;
}
set
{
_activeStudents = value;
RaisePropertyChanged("GridDisplay");
}
}
现在我的Xaml
<xctk:CheckListBox Height="200"
ItemsSource="{Binding Path=ActiveStudents, Mode=TwoWay}"
Name="ActiveStudents"
DisplayMemberPath="Student"
ValueMemberPath="StudentID"
SelectedMemberPath="Select"
SelectedItem="{Binding SelectedStudent}"
SelectedItemsOverride="{Binding SelectedStudentValue}"/>
<DataGrid MaxHeight="200" MinHeight="200" Name="MyGrid"
Grid.Row="1" Grid.Column="1"
VerticalAlignment="Top"
HeadersVisibility="Column"
AutoGenerateColumns="False"
AlternatingRowBackground="#F0EDF2"
ItemsSource="{Binding GridDisplay}"
VerticalScrollBarVisibility="Auto"
CanUserAddRows="false">
<DataGrid.GroupStyle>.....
.....
最重要的是,我有一个下拉列表,它决定了在复选框中预先检查哪些学生,从而使他们显示在数据网格中。最后一部分我相信我能理解,但我无法让我从复选框中选择的学生显示在数据网格中
任何帮助都将不胜感激 CheckedListBox有一个ItemCheck事件。您可以查看e.Index在事件中选中/取消选中的项目。您还需要查看e.CurrentValue和e.NewValue 一,。如果发布代码,也要发布私有变量(因此,如果有人试图粘贴它并查看它是否有效,他就不需要为所有学生属性添加私有字段)。2.我想你是在使用“检查列表”框吧?如果是,哪个版本?它是wpf工具包中的版本。我相信这是多余的。这是第二版。我已经发布了私有变量。CheckListBox似乎没有ItemCheck事件。我能找到的最接近的是ItemSelectionChanged事件。它已路由EventArgs,因此没有e.CurrentValue或e.NewValue。
<xctk:CheckListBox Height="200"
ItemsSource="{Binding Path=ActiveStudents, Mode=TwoWay}"
Name="ActiveStudents"
DisplayMemberPath="Student"
ValueMemberPath="StudentID"
SelectedMemberPath="Select"
SelectedItem="{Binding SelectedStudent}"
SelectedItemsOverride="{Binding SelectedStudentValue}"/>
<DataGrid MaxHeight="200" MinHeight="200" Name="MyGrid"
Grid.Row="1" Grid.Column="1"
VerticalAlignment="Top"
HeadersVisibility="Column"
AutoGenerateColumns="False"
AlternatingRowBackground="#F0EDF2"
ItemsSource="{Binding GridDisplay}"
VerticalScrollBarVisibility="Auto"
CanUserAddRows="false">
<DataGrid.GroupStyle>.....