This is a migrated thread and some comments may be shown as answers.

[Solved] Filter by binding with a second GridView

3 Answers 170 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bij
Top achievements
Rank 1
Bij asked on 26 Jul 2010, 01:01 PM

Hey,

I have a Problem on Binding the filtered value in a RadGridView.
I have two UserControls with one GridView each in one Window (sharing DataContext -ObervableCollection<Element>-) and I would like to filter the entries in one of them (radGridView2), where the value to filter by is the value of the currently SelecteItem of the other GridView (radGridView1). How can I do this?
With the following code: 

In Element.cs:
class Element
{
    string Name;
}

In radGridView1.xaml:
...
<telerik:RadGridView x:Name="radGridView1" AutoGenerateColumns="False" ForceCursor="True" ItemSource="{Binding}" SelectedItem="Name"\>
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn ... DataMemberBinding="{Binding Name, UpdateSourceTrigger=PropertyChanged}" Header="Name" IsResizable="True">
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

In radGridView2.xaml I would like to do something like this:
...
<telerik:RadGridView x:Name="radGridView2" ShowInsertRow="True" ItemSource="{Binding}"
    <telerik:RadGridView.FilterDescriptors>
        <telerik:RadGridView.FilterDescriptor Member="Name" Operator="IsEqualTo" Value="{Binding radGridView1.SelectedItem.Name}">
...

This is not compiling. Do you know, how I should do it?

Thanks,

Bij.M

Ps: I'm sorry, I cannot directly copy my code, but if it helps, I can retype the rest of it for you.

3 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 28 Jul 2010, 09:01 AM
Hi Bij,

Unfortunately FilterDescriptor is not a DependencyObject yet, but we have plans to make it one. Until then you should add the FilterDescriptor to the grid programatically. You can attach to the selection changed event of the first grid and when selection changes you can add/remove/edit the FilterDescriptor for the second grid.

I hope this helps. Let us know if there are problems.

Regards,
Ross
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
david mcintyre
Top achievements
Rank 1
answered on 19 Oct 2010, 09:56 PM
Hi Ross, can you provide me w/ a snippet on how to do this?  I have the same scenario and problem as Bij.  In the first grid's SelectionChanged event handler, i can't clear or remove the grid's filterdescriptors without getting a InvalidOperationException ("Cannot change observablecollection during a collecctionchanged or propertychanged event").  I can see how you can't change the filterdescriptors of the *first* grid, but i don't understand why it's preventing the change to another grid's filters. 

Update:  I remembered that observable collections trigger updates only when adding/removing members, so i can edit the filter descriptor's value.  Is this the best or only way to do this?
0
Veselin Vasilev
Telerik team
answered on 21 Oct 2010, 03:03 PM
Hi david mcintyre,

Please find attached a sample project.

Kind regards,
Veselin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Bij
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
david mcintyre
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or