Question

I am trying to change the filter settings to "contains" instead of "begins with" inside a XamDataGrid, Is there any property that allows implementing the functionality?

I was unable to find it after much research, would be great if someone could help me find if there is something I missed.

Was it helpful?

Solution 2

Got the property I needed, Thanks everyone.

It goes like this,

    <igDP:Field Name="Description">
                                <igDP:Field.Settings>
                                    <igDP:FieldSettings
AllowGroupBy="True"
AllowEdit="True"
AllowRecordFiltering="True"
FilterOperatorDefaultValue="Contains"/>                                        
                                </igDP:Field.Settings>    
                            </igDP:Field>

OTHER TIPS

If you would rather filter in your ViewModel, here is an example that demonstrates how you would use ICollectionView:

public class TestViewModel : INotifyPropertyChanged
{
    private string _filterText;
    private List<string> _itemsList;

    public TestViewModel()
    {
        _itemsList = new List<string>() { "Test 1", "Test 2", "Test 3" };
        this.Items = CollectionViewSource.GetDefaultView(_itemsList);
        this.Items.Filter = FilterItems;
    }

    public ICollectionView Items { get; private set; }

    public string FilterText
    {
        get { return _filterText; }
        set
        {
            _filterText = value;
            Items.Refresh();
            this.RaisePropertyChanged("FilterText");
        }
    }

    private bool FilterItems(object item)
    {

        return this.FilterText == null || item.ToString().Contains(this.FilterText);
    }


    #region INotifyPropertyChanged Members

    public event PropertyChangedEventHandler PropertyChanged;

    private void RaisePropertyChanged(string propName)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propName));
    }
    #endregion
}

Then in your View, you just DataBind the TextBox to the FilterText property and the ItemsSource or Grid to the Items property (demonstrated with a ListBox here):

<TextBox x:Name="ItemsFilter" Text="{Binding FilterText, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Width="100" Margin="10" VerticalAlignment="Center"/>
<ListBox x:Name="ItemsList" ItemsSource="{Binding Items}" Grid.Row="1" Width="200" Margin="10" HorizontalAlignment="Left"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top