简体   繁体   English

带复选框的 WPF 数据网格过滤器

[英]WPF datagrid filter with checkboxes

I have a datagrid in WPF with the columns first name, last name, hours, and grade.我在 WPF 中有一个数据网格,其中包含名字、姓氏、小时数和等级。 I want to filter it with checkboxes to only show the something like people with >200 hours, or only people in 9th grade.我想用复选框过滤它,只显示那些工作时间超过 200 小时的人,或者只显示 9 年级的人。 I want it to be dynamic so you can check and uncheck the checkbox and the datagrid would dynamically filter for all the checked ones.我希望它是动态的,因此您可以选中和取消选中复选框,数据网格将动态过滤所有选中的复选框。 For example, only those in 9th and 10th grade with <100 hours would be 3 checkboxes, the 9th grade, 10th grade, and the <100 hours filter all applied to the Datagrid.例如,只有 9 年级和 10 年级<100 小时的学生才会有 3 个复选框,9 年级、10 年级和 <100 小时过滤器都应用于 Datagrid。 Can someone help, I haven't been able to find what i'm looking for.有人可以帮忙吗,我一直无法找到我要找的东西。

 class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public int ID { get; set; }
        public int Grade { get; set; }
        public double Hours { get; set; }
    }

List<Person> people = new List<Person>()

Then in wpf, I have a simple datagrid where I make the TestDatagrid.itemsource= people and I want to filter the datagrid programmatically with a set of checkboxes.然后在 wpf 中,我有一个简单的数据网格,我在其中创建了TestDatagrid.itemsource= people并且我想用一组复选框以编程方式过滤数据网格。

What about LINQ? LINQ呢? like Checkbox.IsChecked TestDatagrid.itemsource = people.Where(p => p.Grade > 100).Select(p =>p);像 Checkbox.IsChecked TestDatagrid.itemsource = people.Where(p => p.Grade > 100).Select(p =>p); May be the syntax is wrong - I have not installed VisualStudio on this computer.可能是语法错误 - 我没有在这台电脑上安装 VisualStudio。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM