WPF过滤数据集DataGrid

时间:2017-12-02 21:59:06

标签: c# wpf datagrid filtering

我稍微修改过这个。我的请求是帮助创建基于两个复选框的过滤器(checkBoxSD& CheckBoxTech)如果两者都勾选,我想看到分配给SD的所有行是Tech或Service Desk。如果勾选了一个,我只想查看具有该名称的行。

<Window x:Class="WpfApp1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApp1"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Window.Resources>
    <local:Database3DataSet x:Key="database3DataSet"/>
    <CollectionViewSource x:Key="live_DataViewSource" Source="{Binding Live_Data, Source={StaticResource database3DataSet}}"/>
</Window.Resources>
<Grid DataContext="{StaticResource live_DataViewSource}">
    <DataGrid x:Name="live_DataDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding}" Margin="0,76,120,46.5" RowDetailsVisibilityMode="VisibleWhenSelected">
        <DataGrid.Columns>
            <DataGridTextColumn x:Name="iDColumn" Binding="{Binding ID}" Header="ID" Width="SizeToHeader"/>
            <DataGridTextColumn x:Name="sD_Assign_toColumn" Binding="{Binding SD Assign to}" Header="SD Assign to" Width="SizeToHeader"/>
        </DataGrid.Columns>
    </DataGrid>
    <CheckBox x:Name="CheckBoxTech" Content="Tech" HorizontalAlignment="Left" Margin="80,45,0,0" VerticalAlignment="Top" RenderTransformOrigin="-1.08,-2.533"/>
    <CheckBox x:Name="checkBoxSD" Content="Service Desk" HorizontalAlignment="Left" Margin="116,10,0,0" VerticalAlignment="Top"/>

</Grid>

我被问到Collection视图源,是吗?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {

        WpfApp1.Database3DataSet database3DataSet = ((WpfApp1.Database3DataSet)(this.FindResource("database3DataSet")));
        // Load data into the table Live_Data. You can modify this code as needed.
        WpfApp1.Database3DataSetTableAdapters.Live_DataTableAdapter database3DataSetLive_DataTableAdapter = new WpfApp1.Database3DataSetTableAdapters.Live_DataTableAdapter();
        database3DataSetLive_DataTableAdapter.Fill(database3DataSet.Live_Data);
        System.Windows.Data.CollectionViewSource live_DataViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("live_DataViewSource")));
        live_DataViewSource.View.MoveCurrentToFirst();
    }

    private void live_DataDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {

    }
}
}

也许我对这项任务太过极了。

由于

菲尔

0 个答案:

没有答案