Results 1 to 4 of 4

Thread: Filtering a datagridview on two fields

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Location
    Oklahoma, USA
    Posts
    92

    Unhappy Filtering a datagridview on two fields

    I am hoping someone can help me. I am converting a Winform app to WPF. Sounded simple when my boss told me that's what I was going to do. But I have already ran into a problem. On the window below I have a DataGridview. The user selects a Category and the datagridview shows all the Campaigns for that Category. There are four types of entries Standard\Test\Control\Notes also Campaigns begin and end so the user only wants to see campaigns the were active for the date they enter. So what I need to do is figure out how to get the Datagridview to only show them what they want. I have included what code I have. I have read a lot about CollectionViewSource filtering but am fussy on how I apply it. I hope someone can help. Thanks


    Name:  Untitled.jpg
Views: 456
Size:  20.1 KB


    HTML Code:
    <Window x:Class="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="450" Width="800">
        <Window.Resources>
            <local:Inq_FULF_DataDataSet x:Key="Inq_FULF_DataDataSet"/>
            <CollectionViewSource x:Key="CategoryViewSource" Source="{Binding Category, Source={StaticResource Inq_FULF_DataDataSet}}"/>
            <CollectionViewSource x:Key="CategoryCampaignViewSource" Source="{Binding FK_Campaign_Category, Source={StaticResource CategoryViewSource}}"/>
        </Window.Resources>
    
    
        <Grid DataContext="{StaticResource CategoryCampaignViewSource}" Margin="0,1,0,-1">
            <Grid x:Name="Grid1" DataContext="{StaticResource CategoryViewSource}" HorizontalAlignment="Left" Margin="33,12,0,0" VerticalAlignment="Top" Width="591">
    
                <Label Content="CAT Category:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
                <ComboBox x:Name="CAT_CategoryComboBox" DisplayMemberPath="CAT_Category" HorizontalAlignment="Left" Height="Auto" ItemsSource="{Binding}" Margin="94,6,0,4" Grid.Row="0" VerticalAlignment="Center" Width="487">
                    <ComboBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel/>
                        </ItemsPanelTemplate>
                    </ComboBox.ItemsPanel>
                </ComboBox>
            </Grid>
    
            <!-- Select Date  R T L B -->
            <DatePicker x:Name="dtpSelDate" SelectedDate="2000-12-31" SelectedDateFormat="Short" Margin="644,61,34,323"/>
    
            <!-- Campaign Type -->
            <GroupBox Header="Campaign Type" Margin="36,51,440,308" BorderBrush="Black" BorderThickness="1">
                <Grid Margin="0,-2,0,2" >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="53*"/>
                        <ColumnDefinition Width="2*"/>
                    </Grid.ColumnDefinitions>
    
                    <RadioButton x:Name="rbStandard"    Content="Standard" GroupName="CampType" HorizontalAlignment="Left"  Margin="0,10,0,2"     VerticalAlignment="Center" Height="16" Width="73" RenderTransformOrigin="-0.562,1.8"/>
                    <RadioButton x:Name="rbTest"            Content="Test"         GroupName="CampType" HorizontalAlignment="Left"  Margin="74,10,0,2"   VerticalAlignment="Center" Height="16" Width="51"/>
                    <RadioButton x:Name="rbControl"       Content="Control"    GroupName="CampType" HorizontalAlignment="Left"  Margin="124,10,0,2" VerticalAlignment="Center" Height="16" Width="70" RenderTransformOrigin="-1.5,-1.667"/>
                    <RadioButton x:Name="rbNote"           Content="Note"        GroupName="CampType" HorizontalAlignment="Left"  Margin="194,10,0,2" VerticalAlignment="Center" Height="16" Width="55"/>
    
                </Grid>
            </GroupBox>
    
            <DataGrid x:Name="CampaignDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" ItemsSource="{Binding}" Margin="36,116,34,103" RowDetailsVisibilityMode="VisibleWhenSelected" IsReadOnly="True">
                <DataGrid.Columns>
                    <DataGridTextColumn x:Name="CM_Cat_IDColumn" Binding="{Binding CM_Cat_ID}" Header="CM Cat ID" Width="SizeToHeader" Visibility="Hidden"/>
                    <DataGridTextColumn x:Name="Cam_IDColumn" Binding="{Binding Cam_ID}" Header="Cam ID" IsReadOnly="True" Width="SizeToHeader" Visibility="Hidden"/>
                    <DataGridTextColumn x:Name="CM_TestFlagColumn" Binding="{Binding CM_TestFlag}" Header="CM Test Flag" Width="SizeToHeader" Visibility="Hidden"/>
                    <DataGridTextColumn x:Name="TestFlagLitColumn" Binding="{Binding TestFlagLit}" Header="S\T" IsReadOnly="True" Width="50"/>
                    <DataGridTextColumn x:Name="CM_CampaignColumn" Binding="{Binding CM_Campaign}" Header="CM Campaign" Width="250"/>
                    <DataGridTextColumn x:Name="CM_CamTypeColumn" Binding="{Binding CM_CamType}" Header="CM Cam Type" Width="250"/>
                    <DataGridTextColumn x:Name="CM_BDateColumn" Binding="{Binding CM_BDate, StringFormat='MM/dd/yyy'}" Header="CM BDate" Width="80"/>
                    <DataGridTextColumn x:Name="CM_EDateColumn" Binding="{Binding CM_EDate, StringFormat='MM/dd/yyy'}" Header="CM EDate" Width="80"/>
                </DataGrid.Columns>
            </DataGrid>
    
        </Grid>
    </Window>
    Code:
    Class MainWindow
        Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs) Handles MyBase.Loaded
    
            Dim Inq_FULF_DataDataSet As WpfApp1.Inq_FULF_DataDataSet = CType(Me.FindResource("Inq_FULF_DataDataSet"), WpfApp1.Inq_FULF_DataDataSet)
            'Load data into the table Category. You can modify this code as needed.
            Dim Inq_FULF_DataDataSetCategoryTableAdapter As WpfApp1.Inq_FULF_DataDataSetTableAdapters.CategoryTableAdapter = New WpfApp1.Inq_FULF_DataDataSetTableAdapters.CategoryTableAdapter()
            Inq_FULF_DataDataSetCategoryTableAdapter.Fill(Inq_FULF_DataDataSet.Category)
            Dim CategoryViewSource As System.Windows.Data.CollectionViewSource = CType(Me.FindResource("CategoryViewSource"), System.Windows.Data.CollectionViewSource)
            CategoryViewSource.View.MoveCurrentToFirst
    
            'Load data into the table Campaign. You can modify this code as needed.
            Dim Inq_FULF_DataDataSetCampaignTableAdapter As WpfApp1.Inq_FULF_DataDataSetTableAdapters.CampaignTableAdapter = New WpfApp1.Inq_FULF_DataDataSetTableAdapters.CampaignTableAdapter()
            Inq_FULF_DataDataSetCampaignTableAdapter.Fill(Inq_FULF_DataDataSet.Campaign)
            Dim CategoryCampaignViewSource As System.Windows.Data.CollectionViewSource = CType(Me.FindResource("CategoryCampaignViewSource"), System.Windows.Data.CollectionViewSource)
            CategoryCampaignViewSource.View.MoveCurrentToFirst
    
        End Sub
    End Class
    Last edited by wjburke2; Mar 23rd, 2022 at 07:58 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,274

    Re: Filtering a datagridview on to fields

    For the record, the DataGridView is a WinForms control. You're using a DataGrid in a WPF app, so not the same thing. I thought you might have posted the right control name in the wrong forum but you actually posted the wrong control name in the right forum.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Location
    Oklahoma, USA
    Posts
    92

    Re: Filtering a datagridview on to fields

    Quote Originally Posted by jmcilhinney View Post
    For the record, the DataGridView is a WinForms control. You're using a DataGrid in a WPF app, so not the same thing. I thought you might have posted the right control name in the wrong forum but you actually posted the wrong control name in the right forum.
    I'm sorry the last thing I want to do is get someone else confused, I'm confused enough as it is. Is that because they removed the View source.
    Last edited by wjburke2; Mar 23rd, 2022 at 07:55 AM.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,274

    Re: Filtering a datagridview on to fields

    Quote Originally Posted by wjburke2 View Post
    Is that because they removed the View source.
    DataGrid is the preferred name and WinForms does have a control with that name, released with the very first edition. It's a bit dodgy though and Microsoft realised that, so they created a new control that was released with .NET 2.0 and VS 2005. They could just replace the old control though, because there were plenty of apps already using it, so the new control had to be added alongside it with a different name. The documentation for the old DataGrid control is here. That's for .NET Framework 4.8. Everything had to be reimplemented for .NET Core and, as that page says, the DataGrid control was not included in that because it's not intended to be used in any new development.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width