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

DataFilter Custom Editor in code

4 Answers 128 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
Martin Durao
Top achievements
Rank 1
Martin Durao asked on 15 Mar 2011, 08:36 PM
Hello

At this time I'm creating in unbound mode the ItemPropertyDefinition's based on the information I get for a list called 'fieldsInfo'.

 ItemPropertyDefinition f = new ItemPropertyDefinition();
 f.PropertyName = column.UniqueName;
 f.DisplayName = fieldsInfo.Label;
 f.PropertyType = ((Telerik.Windows.Controls.GridViewBoundColumnBase)(column)).DataType;
 filterArray.Add(f);
.......
this.dataFilter.Source = null; //Unbound mode
this.dataFilter.ItemPropertyDefinitions.Clear();
this.dataFilter.ItemPropertyDefinitions.AddRange(filterArray.AsEnumerable());

Now I would need to create dinamically custom editors (ComboBoxes) for some of this fields that show a text and set a value to send back to server. Of course ComboBoxes will be fed from a list with text and value properties.

It is for a generic control and I didn't know which field will be affected at design time.
The question is, could I do that in code without EditorTemplateRules in XALM?

Thanks in advance
Martin

4 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 16 Mar 2011, 09:54 AM
Hello Martin Durao,

That is quite possible.

Our particular implementation of a TemplateSelector in this online sample is one that allows you to define templates in XAML. But your implementation does not have to be the same.

The beauty of the TemplateSelector is that it has only one method which will called at run-time on order to select the template. You will receive the name and type of the property as a parameter and based on that information you have to return the appropriate editor:

public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
            ItemPropertyDefinition propertyDefinition = (ItemPropertyDefinition)item;
 
//Here you can return any DataTemplate that you want based on the information contained in the propertyDefinition... you can keep all possible DataTemplates as static resources for example...
 
}

Take a look at this article to learn more about TemplateSelectors.

I hope this helps.


Kind regards,
Ross
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Martin Durao
Top achievements
Rank 1
answered on 17 Mar 2011, 08:15 AM
Hello Ross

I did what you said and it works fine. The only problem I've now is that combobox selected value is not present at filter descriptor that always remain <Unset> even when at selection changed event I can see combobox has a value.

ComboBox ItemsSource is fed with a list with two fields Value an Title.

Could you help me please?




    <DataTemplate x:Key="DXComboTemplateItem">
            <telerik1:RadComboBox SelectedValue="{Binding Value, Mode=TwoWay, FallbackValue=null}"
                            MinWidth="200"
                            SelectionChanged="RadComboBox_SelectionChanged"
                            telerik:TextSearch.TextPath="Title"
                            SelectedValuePath="Value"
                            DisplayMemberPath="Title"/>
    </DataTemplate>

    <DXControls:DXTemplateSelector x:Key="filterTemplateSelector"
                                   DXComboTemplate="{StaticResource DXComboTemplateItem}"/>



0
Rossen Hristov
Telerik team
answered on 17 Mar 2011, 09:47 AM
Hello Martin Durao,

That sounds very weird. We are doing absolutely the same thing in the online example that I mentioned and it works, i.e.:

<!--EditorTemplate for the Name property.-->
            <DataTemplate x:Key="NameFilterEditorTemplate">
                <telerik:RadComboBox SelectedValue="{Binding Value, Mode=TwoWay, FallbackValue=null}"
                                     MinWidth="100"/>
            </DataTemplate>

What are the differencess between the online sample and your project?

Could you please open a separate support ticket and attach a small sample project. It can be a very dummy one, i.e. only with the code that is needed to demonstrate this.

I will take a look at it to see what is going on.

Kind regards,
Ross
the Telerik team
0
Martin Durao
Top achievements
Rank 1
answered on 17 Mar 2011, 12:18 PM
Hello Ross

I don't know why but this is working fine now...
Thanks for your support!

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