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

Trying to use converter on DistinctValues

8 Answers 162 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
Eli
Top achievements
Rank 1
Eli asked on 17 Dec 2012, 04:02 PM
Hello,

I styled the FilteringControl on a RadGrid to include a converter on the list of distinct values to filter by.

I am using this code in the converter,

            var filter = value as FilteringViewModel;
            if (filter != null)
            {
                foreach (DistinctValueViewModel distinctValue in filter.DistinctValues)
                {
                    
                }
                return filter.DistinctValues;
            }

            return null;

But when I put a breakpoint on the code it says that DistinctValues.Count = 0 and the loop will not trigger.

However, after the converter returns it's value, it shows the distinct values correctly.

I am wondering why I cannot access the distinct list inside the converter because I know it returns the right value.

Thank you,

8 Answers, 1 is accepted

Sort by
0
Eli
Top achievements
Rank 1
answered on 17 Dec 2012, 05:27 PM
Also, I am trying to access the column the filters belong to using var column = filter.GetType().GetField("column"); and it is returning null. How can I get access to the column from within the filter?
0
Vlad
Telerik team
answered on 18 Dec 2012, 07:39 AM
Hi,

 I'm not sure how this is related to RadDataFilter. Can you clarify? 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Eli
Top achievements
Rank 1
answered on 18 Dec 2012, 02:00 PM
Doesn't the FilteringControl from the grid inherited from the RadDataFilter?
0
Vlad
Telerik team
answered on 18 Dec 2012, 02:22 PM
Hello,

 Actually no. Both are completely different and independent. 

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Eli
Top achievements
Rank 1
answered on 18 Dec 2012, 02:24 PM
Okay, how do I solve the problem?
0
Eli
Top achievements
Rank 1
answered on 26 Dec 2012, 03:50 PM
Is this still an open question?
0
Eli
Top achievements
Rank 1
answered on 31 Dec 2012, 05:30 PM
Hello? anyone here?
0
Rossen Hristov
Telerik team
answered on 02 Jan 2013, 08:04 AM
Hi,

Distinct values are loaded and shaped on demand. We are using our own conversion logic in order to shape how the distinct values look in the UI. Here is how we do it:
<ListBox x:Name="PART_DistinctValuesList"
     ItemsSource="{Binding DistinctValues}"
     telerik:StyleManager.Theme="{StaticResource Theme}"
     ScrollViewer.HorizontalScrollBarVisibility="Auto"
     SelectionMode="Multiple" ItemContainerStyle="{StaticResource DistinctValueListBoxItemStyle}">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <VirtualizingStackPanel  MaxHeight="242"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding IsActive, Mode=TwoWay}"
                  Content="{Binding ConvertedValue, Converter={StaticResource DistinctValueConverter}}"
                  VerticalContentAlignment="Center"
                  telerik:StyleManager.Theme="{StaticResource Theme}"/>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

So if you want to replace our stock converter with your one you can do it directly in the XAML. Alongside with the ConvertedValue property, the DistinctValueViewModel has another property called RawValue. So you can do something like this in XAML and the raw distinct value will be entering your converter:
<CheckBox IsChecked="{Binding IsActive, Mode=TwoWay}"
 
                  Content="{Binding RawValue, Converter={StaticResource YourConverter}}"
 
                  VerticalContentAlignment="Center"
 
                  telerik:StyleManager.Theme="{StaticResource Theme}"/>

The result of what your converter returns will be displayed in the UI as the content of the check-box.

I hope this helps. Also, placing a question in the correct product forum is always a good idea. RadDataFilter is an independent control that has absolutely nothing to do with RadGridView.

Regards,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
DataFilter
Asked by
Eli
Top achievements
Rank 1
Answers by
Eli
Top achievements
Rank 1
Vlad
Telerik team
Rossen Hristov
Telerik team
Share this question
or