Exception when toggling columns visibility using search panel

1 Answer 114 Views
GridView
Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
Eldoir asked on 11 Jan 2022, 03:24 PM | edited on 11 Jan 2022, 04:23 PM

Hi,

I'm trying to toggle the visibility of my columns based on the input of the search panel. My goal is to achieve something similar to this.

So I have created a very simple behavior like this:

internal class SearchColumnsByNameBehavior : Behavior<RadGridView>
{
    protected override void OnAttached()
    {
        base.OnAttached();

        AssociatedObject.ShowSearchPanel = true;
        AssociatedObject.Searching += OnSearching;
    }

    protected override void OnDetaching()
    {
        AssociatedObject.Searching -= OnSearching;

        base.OnDetaching();
    }

    private void OnSearching(object sender, GridViewSearchingEventArgs args)
    {
        foreach (GridViewColumn column in AssociatedObject.Columns)
        {
            string columnHeader = column.Header?.ToString();

            if (!string.IsNullOrEmpty(columnHeader))
            {
                column.IsVisible = columnHeader.Contains(args.SearchText);
            }
        }
    }
}

Unfortunately, when typing text in the textbox of the search panel, I get the following exception:

'No coercion operator is defined between types 'System.String' and 'MyProject.SomeClass+MyEnum'

Where 'MyEnum' is  of type:

[Flags] enum MyEnum : ulong

Looks like there are things done under the hood of the search panel that I don't know about, or is it the '+' that is actually the real problem here?

What am I supposed to do? Thanks in advance!

 

Full stacktrace:

System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow(ExpressionType coercionType, Expression expression, Type convertToType)
   at Telerik.Windows.Data.Expressions.FilterDescriptorExpressionBuilder.CreateLeftOperandExpression()
   at Telerik.Windows.Data.Expressions.OperatorValueFilterDescriptorExpressionBuilderBase.CreateBodyExpressionThreadSafe()
   at Telerik.Windows.Data.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpressionThreadSafe()
   at Telerik.Windows.Data.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpressionThreadSafe()
   at Telerik.Windows.Data.Expressions.FilterDescriptorCollectionExpressionBuilder.CreateBodyExpressionThreadSafe()
   at Telerik.Windows.Data.Expressions.FilterExpressionBuilder.CreateFilterExpression()
   at Telerik.Windows.Data.QueryableExtensions.Where(IQueryable source, CompositeFilterDescriptorCollection filterDescriptors)
   at Telerik.Windows.Data.QueryableCollectionView.CreateView()
   at Telerik.Windows.Data.QueryableCollectionView.CreateInternalList()
   at Telerik.Windows.Data.QueryableCollectionView.get_InternalList()
   at Telerik.Windows.Data.QueryableCollectionView.get_InternalCount()
   at Telerik.Windows.Data.QueryableCollectionView.get_IsEmpty()
   at Telerik.Windows.Controls.GridView.BaseItemsControl.OnItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.DataItemCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.DataItemCollection.OnCollectionViewCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
   at Telerik.Windows.Data.QueryableCollectionView.RefreshOverride()
   at Telerik.Windows.Data.QueryableCollectionView.RefreshOrDefer()
   at Telerik.Windows.Data.QueryableCollectionView.InvalidatePagingAndRefresh()
   at Telerik.Windows.Data.QueryableCollectionView.OnFilterDescriptorsChanged()
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.RadObservableCollection`1.ResumeNotifications()
   at Telerik.Windows.Data.CollectionHelper.Reset(IEnumerable source, IList target, Func`2 itemConverter)
   at Telerik.Windows.Data.ObservableCollectionManager.HandleCollectionChanged(IList sender, NotifyCollectionChangedEventArgs args)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at Telerik.Windows.Data.RadObservableCollection`1.ResumeNotifications()
   at Telerik.Windows.Controls.GridView.SearchPanel.SearchViewModel.set_SearchText(String value)'

1 Answer, 1 is accepted

Sort by
0
Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
answered on 12 Jan 2022, 04:41 PM | edited on 12 Jan 2022, 04:41 PM

Hello again,

I don't think my problem is a "real one" actually. I believe I was trying to use the SearchPanel in an unintended way.
What I really wanted was to filter on column header's, however the search panel really is useful to search through cells.

So I just used a regular TextBox instead of the search panel and bound my behavior to its text value, in a way similar to what I showed above.

It's working great! So you're free to archive this if you want.

Have a great day,

Arthur

Stenly
Telerik team
commented on 13 Jan 2022, 10:35 AM

Hello Arthur,

Indeed, the SearchPanel is meant for searching the RadGridView cells by matching the input value with each cell's represented data, and not for searching the columns. With that said, I am happy to hear that you have found a suitable solution to your question and that you took the time to share it with us. Let us know if you need any further assistance.

Tags
GridView
Asked by
Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Eldoir
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or