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

DataFilter DataTemplate

5 Answers 83 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
WILLIAM
Top achievements
Rank 1
WILLIAM asked on 22 Jun 2012, 12:37 AM
I'm a little confused on how to create a data template in code (not xaml).  I'm wanting to use a combo box.  I have created my own class that inherits from DataTemplateSelector, and in this class, I create as many DataTemplate properties as I need.  What I can't seem to figure out is where to specify the type of control.  I'm trying DataTemplate.Type = typeof(RadComboBox), but in the EditorCreated event, it's still a TextBox.

Where do I specify the type of editor?

i.e.  I want to be able to do the following, but in the codebehind:

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

Thanks!

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 22 Jun 2012, 10:11 AM
Hi,

 Have you already checked this help article?

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
WILLIAM
Top achievements
Rank 1
answered on 22 Jun 2012, 01:57 PM
Yes I have, but it doesn't give any examples of what I'm trying to do.  In the xaml there is the code example below.  But I want to do this in code behind, not in the xaml.  Can you point me to an example

<DataTemplate x:Key="ComboBoxEditor">
       <telerik:RadComboBox SelectedValue="{Binding Value, Mode=TwoWay, FallbackValue=null}" MinWidth="100" />
</DataTemplate>
0
WILLIAM
Top achievements
Rank 1
answered on 22 Jun 2012, 04:05 PM
I'm slowly getting through this, but it does seem to be working.  So let me ask this one question to see if understand correctly how this is supposed work.

When EditorSelector.SelectTemplate is called, I loop through the rules and if I find a match, I return the DataTemplate from that rule.  Is that correct?

Assuming that the data template I return is of the correct type (in my case a RadComboBox) when the EditorCreated event is fired, shouldn't the Editor be of type RadComboBox?

I have my rules setup, and when debugging, the SelectTemplate method returns a combobox correctly, but when the EditorCreated event is fired, the editor is a TextBox.

Can anyone help me understand the disconnect that I seem to be having?

public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var ipd = item as ItemPropertyDefinition;
            if (ipd == null) return base.SelectTemplate(item, container);
 
            foreach(var etr in EditorTemplateRules)
            {
                //this if statement works correctly and returns a RadComboBox when needed
                if (etr.PropertyName == ipd.PropertyName) return etr.DataTemplate;
            }
 
            return base.SelectTemplate(item, container);
        }
 
private void DataFilterEditorCreated(object sender, EditorCreatedEventArgs e)
{
      var rcb = ((RadComboBox) e.Editor);            //e.Editor is always a TextBox
0
Rossen Hristov
Telerik team
answered on 27 Jun 2012, 07:50 AM
Hello,

Can you please send us a very small runnable dummy project which demonstrates the behavior you are faced with. We will take a look to see what is going on.

Thanks in advance.

Greetings,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Dimitrina
Telerik team
answered on 27 Jun 2012, 08:26 AM
Hi,

 Would it be possible for you to isolate the problem you have met in a demo project and send it to us? That way we could explain better.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

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