Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

combobox filtering

$
0
0

Hi

Okay, I have an my ListBox bound to an observablecollection(of IGeneric) called Rules. Currently there are two type of rules.

So I have two datatemplates defined for those two types of rules. so each listboxitem uses the correct datatemplate

each datatemplate has a combobox bound to a an observablecollection(Of IRule) called Operators

Rule1) can display the following {"=", ">", "<", "<>","Between"}

Rule2) can display the following {"=", ">", "<", "<>"}

I want to filter the combobox and remove "Between" when listboxitem is displaying rule2????

I tried using ICollectionView.Filter,

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SandBox"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    xmlns:assets="clr-namespace:SandBox.Assets"
    Title="MainWindow" Height="350" Width="800"><Window.Resources><DataTemplate  DataType="{x:Type local:FieldRule}"><GroupBox Header="Field Rule"><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="1*"></ColumnDefinition><ColumnDefinition Width="1*"></ColumnDefinition><ColumnDefinition Width="1*"></ColumnDefinition><ColumnDefinition Width="1*"></ColumnDefinition><assets:ColumnDefinitionExtended Width="1*" Visible="False"></assets:ColumnDefinitionExtended><assets:ColumnDefinitionExtended Width="1*" Visible="False"></assets:ColumnDefinitionExtended><ColumnDefinition Width="50"></ColumnDefinition></Grid.ColumnDefinitions><ComboBox Grid.Column="0"  Margin="3"
                              ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Concatenations}"
                              SelectedValue="{Binding Concatenation}"
                              DisplayMemberPath="Text"/><ComboBox Grid.Column="1"  Margin="3"                              
                              ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Fields}"
                              SelectedValue="{Binding Field}"
                              DisplayMemberPath="Text"/><ComboBox Grid.Column="2" Margin="3" SelectionChanged="ComboBox_SelectionChanged"                              
                              ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Operators}"
                              SelectedValue="{Binding Operation}"
                              DisplayMemberPath="Text"/><TextBox Grid.Column="3" Margin="3"/><ComboBox Grid.Column="4"  Margin="3"
                              ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Concatenations}"
                              SelectedValue="{Binding Operation1}"
                              DisplayMemberPath="Text"/><TextBox Grid.Column="5"  Margin="3"/><Button Content="Delete"
                                Grid.Column="6"
                                    Click="Button_Click"/></Grid></GroupBox></DataTemplate><DataTemplate  DataType="{x:Type local:StandardRule}"><GroupBox Header="Standard Rule"><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="1*"></ColumnDefinition><ColumnDefinition Width="1*"></ColumnDefinition><ColumnDefinition Width="1*"></ColumnDefinition><ColumnDefinition Width="1*"></ColumnDefinition><ColumnDefinition Width="1*"></ColumnDefinition><ColumnDefinition Width="1*"></ColumnDefinition><ColumnDefinition Width="50"></ColumnDefinition></Grid.ColumnDefinitions><ComboBox Grid.Column="0"  Margin="3"
                              ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Concatenations}"
                              SelectedValue="{Binding Concatenation}"
                              DisplayMemberPath="Text"/><ComboBox Grid.Column="1"  Margin="3"
                              ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=HeaderItems}"
                              SelectedValue="{Binding Field}"
                              DisplayMemberPath="Text"/><ComboBox Grid.Column="2" Margin="3"                              
                              ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=Operators}"
                              SelectedValue="{Binding Operation}"
                              DisplayMemberPath="Text"/><ComboBox Grid.Column="3"  Margin="3"
                              ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ConfigOptions}"
                              SelectedValue="{Binding Operand}"
                              DisplayMemberPath="Text"/><!--<ComboBox Grid.Column="4" Text="{Binding LastName}" Margin="3"/>--><Button Content="Delete"
                                Grid.Column="6"
                                    Click="Button_Click"/></Grid></GroupBox></DataTemplate></Window.Resources><Grid><DockPanel ScrollViewer.CanContentScroll="True"><ItemsControl ItemsSource="{Binding Rules}"
                          Name="MyItemsControl"
                          DockPanel.Dock="Top"></ItemsControl><telerik:RadDropDownButton Content="Add" 
                                        Height="23" 
                                        Name="RadDropDownButton1" 
                                        Width="75"
                                        DockPanel.Dock="Bottom"
                                        VerticalAlignment="Bottom"
                                        HorizontalAlignment="Right"><telerik:RadDropDownButton.DropDownContent><StackPanel><TextBlock Width="125" Text="Field Rule" MouseLeftButtonDown="TextBlock_MouseLeftButtonDown"/><TextBlock Width="125" Text="Standard Rule" MouseLeftButtonDown="TextBlock_MouseLeftButtonDown"/></StackPanel></telerik:RadDropDownButton.DropDownContent></telerik:RadDropDownButton></DockPanel></Grid></Window>
Imports System.Collections.ObjectModel

Class MainWindow

    Private mRules As ObservableCollection(Of IGeneric)
    Private mConcatenations As ObservableCollection(Of IRule)
    Private mFields As ObservableCollection(Of IRule)
    Private mOperators As ObservableCollection(Of IRule)
    Private mHeaderItems As ObservableCollection(Of IRule)
    Private mConfigOptions As ObservableCollection(Of IRule)

    Public Property Rules() As ObservableCollection(Of IGeneric)
        Get
            Return mRules
        End Get
        Set(ByVal value As ObservableCollection(Of IGeneric))
            mRules = value
        End Set
    End Property

    Public Property Concatenations() As ObservableCollection(Of IRule)
        Get
            Return mConcatenations
        End Get
        Set(value As ObservableCollection(Of IRule))
            mConcatenations = value
        End Set
    End Property

    Public Property Fields() As ObservableCollection(Of IRule)
        Get
            Return mFields
        End Get
        Set(value As ObservableCollection(Of IRule))
            mFields = value
        End Set
    End Property

    Public Property Operators As ObservableCollection(Of IRule)
        Get
            Return mOperators
        End Get
        Set(value As ObservableCollection(Of IRule))
            mOperators = value
        End Set
    End Property

    Public Property HeaderItems As ObservableCollection(Of IRule)
        Get
            Return mHeaderItems
        End Get
        Set(value As ObservableCollection(Of IRule))
            mHeaderItems = value
        End Set
    End Property

    Public Property ConfigOptions As ObservableCollection(Of IRule)
        Get
            Return mConfigOptions
        End Get
        Set(value As ObservableCollection(Of IRule))
            mConfigOptions = value
        End Set
    End Property


    Public Sub New()
        InitializeComponent()

        mConcatenations = New ObservableCollection(Of IRule)
        mConcatenations.Add(New Concatenation() With {.Text = "AND"})
        mConcatenations.Add(New Concatenation() With {.Text = "OR"})

        mFields = New ObservableCollection(Of IRule)
        mFields.Add(New Field() With {.Text = "Size X"})
        mFields.Add(New Field() With {.Text = "Size Y"})
        mFields.Add(New Field() With {.Text = "Size Z"})

        mOperators = New ObservableCollection(Of IRule)
        mOperators.Add(New Operation() With {.Text = "="})
        mOperators.Add(New Operation() With {.Text = ">"})
        mOperators.Add(New Operation() With {.Text = "<"})
        mOperators.Add(New Operation() With {.Text = "<>"})
        mOperators.Add(New Operation() With {.Text = "Between"})

        mHeaderItems = New ObservableCollection(Of IRule)
        mHeaderItems.Add(New HeaderItem() With {.Text = "Color"})

        mConfigOptions = New ObservableCollection(Of IRule)
        mConfigOptions.Add(New ConfigOption() With {.Text = "AllColors"})


        mRules = New ObservableCollection(Of IGeneric)
        mRules.Add(New FieldRule())
        mRules.Add(New StandardRule())
        DataContext = Me
    End Sub



    Private Sub TextBlock_MouseLeftButtonDown(sender As System.Object, e As System.Windows.Input.MouseButtonEventArgs)
        If e.Source.Text = "Field Rule" Then
            mRules.Add(New FieldRule())
        Else
            mRules.Add(New StandardRule())
        End If
    End Sub

    Private Sub ComboBox_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
        If e.AddedItems.Count > 0 Then
            Dim _grid As Grid = Assets.GenericTools.FindAncestorOrSelf(Of Grid)(sender)
            Dim _irule As IRule = TryCast(e.AddedItems.Item(0), IRule)
            If _irule IsNot Nothing Then
                If _irule.Text = "Between" Then
                    DirectCast(_grid.ColumnDefinitions(4), Assets.ColumnDefinitionExtended).Visible = True
                    DirectCast(_grid.ColumnDefinitions(5), Assets.ColumnDefinitionExtended).Visible = True
                Else
                    DirectCast(_grid.ColumnDefinitions(4), Assets.ColumnDefinitionExtended).Visible = False
                    DirectCast(_grid.ColumnDefinitions(5), Assets.ColumnDefinitionExtended).Visible = False
                End If
            End If
        End If
    End Sub

    Private Sub Button_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
        Dim i As IGeneric = sender.DataContext
        mRules.Remove(i)
    End Sub
End Class

Public Interface IGeneric
    Function ToString() As String
End Interface

Public Interface IRule
    Property Text As String
End Interface


Public Class FieldRule
    Implements IGeneric

    Private mConcatenation As IRule
    Private mField As IRule
    Private mOperation As IRule
    Private mOperand As IRule
    Private mOperation1 As IRule
    Private mOperand1 As IRule

    Public Property Concatenation() As IRule
        Get
            Return mConcatenation
        End Get
        Set(ByVal value As IRule)
            mConcatenation = value
        End Set
    End Property

    Public Property Field() As IRule
        Get
            Return mField
        End Get
        Set(ByVal value As IRule)
            mField = value
        End Set
    End Property

    Public Property Operation() As IRule
        Get
            Return mOperation
        End Get
        Set(ByVal value As IRule)
            mOperation = value
        End Set
    End Property
    Public Property Operand() As IRule
        Get
            Return mOperand
        End Get
        Set(ByVal value As IRule)
            mOperand = value
        End Set
    End Property
    Public Property Operation1() As IRule
        Get
            Return mOperation1
        End Get
        Set(ByVal value As IRule)
            mOperation1 = value
        End Set
    End Property
    Public Property Operand1() As IRule
        Get
            Return mOperand1
        End Get
        Set(ByVal value As IRule)
            mOperand1 = value
        End Set
    End Property


    Public Function ToString1() As String Implements IGeneric.ToString
        Return String.Format("{0} {1}", mConcatenation, mField)
    End Function
End Class

Public Class StandardRule
    Implements IGeneric


    Private mConcatenation As IRule
    Private mField As IRule
    Private mOperation As IRule
    Private mOperand As IRule

    Public Property Concatenation() As IRule
        Get
            Return mConcatenation
        End Get
        Set(ByVal value As IRule)
            mConcatenation = value
        End Set
    End Property

    Public Property Field() As IRule
        Get
            Return mField
        End Get
        Set(ByVal value As IRule)
            mField = value
        End Set
    End Property

    Public Property Operation() As IRule
        Get
            Return mOperation
        End Get
        Set(ByVal value As IRule)
            mOperation = value
        End Set
    End Property
    Public Property Operand() As IRule
        Get
            Return mOperand
        End Get
        Set(ByVal value As IRule)
            mOperand = value
        End Set
    End Property

    Public Function ToString1() As String Implements IGeneric.ToString
        Return String.Empty
    End Function
End Class





Public Class Concatenation
    Implements IRule

    Private mText As String

    Public Property Text As String Implements IRule.Text
        Get
            Return mText
        End Get
        Set(value As String)
            mText = value
        End Set
    End Property
End Class

Public Class Field
    Implements IRule

    Private mText As String

    Public Property Text As String Implements IRule.Text
        Get
            Return mText
        End Get
        Set(value As String)
            mText = value
        End Set
    End Property
End Class

Public Class Operation
    Implements IRule

    Private mText As String

    Public Property Text As String Implements IRule.Text
        Get
            Return mText
        End Get
        Set(value As String)
            mText = value
        End Set
    End Property
End Class

Public Class HeaderItem
    Implements IRule

    Private mText As String

    Public Property Text As String Implements IRule.Text
        Get
            Return mText
        End Get
        Set(value As String)
            mText = value
        End Set
    End Property
End Class

Public Class ConfigOption
    Implements IRule

    Private mText As String

    Public Property Text As String Implements IRule.Text
        Get
            Return mText
        End Get
        Set(value As String)
            mText = value
        End Set
    End Property
End Class





Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>