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

Databindings Incorrect

4 Answers 141 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Darren
Top achievements
Rank 1
Darren asked on 16 May 2009, 07:59 PM
Hi,

I am dynamically filling a RadComboBox based on input from the keyboard.  My XAML looks like this:

        <telerikInput:RadComboBox x:Name="MedName" GotFocus="MedName_GotFocus" SelectionChanged="MedName_SelectionChanged" ItemsSource="{Binding IdentifierNameType}" Text="{Binding Name, Mode=TwoWay}" Grid.Row="1"  Grid.Column="1" IsTextSearchEnabled="False" IsEditable="True" Height="20" Width="200" HorizontalAlignment="Left"
            <telerikInput:RadComboBox.ItemTemplate> 
                <DataTemplate> 
                    <StackPanel Orientation="Horizontal"
                        <TextBlock Text="{Binding Name}" /> 
                    </StackPanel> 
                </DataTemplate> 
            </telerikInput:RadComboBox.ItemTemplate> 
        </telerikInput:RadComboBox> 

My IdentifierNameType class looks like this:

        public class IdentifierNameType 
        { 
            private int identifier = 0
            private string name = ""
 
            public IdentifierNameType() { } 
 
            public IdentifierNameType(int identifier, string name) 
            { 
                this.identifier = identifier; 
                this.name = name; 
            } 
 
            [DataMember(Name = "Identifier")] 
            public int Identifier 
            { 
                get 
                { 
                    return this.identifier; 
                } 
                set 
                { 
                    this.identifier = value
                } 
            } 
 
            [DataMember(Name = "Name")] 
            public string Name 
            { 
                get 
                { 
                    return this.name; 
                } 
                set 
                { 
                    this.name = value
                } 
            } 
        } 
 

Everything looks good except for when I actually select an item from the dropdown.  It looks like my bindings are wrong.  How do I set it to where the IdentifierNameType.Name is bound correctly?  What I am seeing in the text portion of the RadComboBox is the class name.

Thanks,
Darren


4 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 18 May 2009, 06:30 AM
Hi Darren ,

Instead of binding the RadComboBox.Text property you need to set the TextSearch.TextPath property:
<telerikInput:RadComboBox telerik:TextSearch.TextPath="Name" ... />

Where telerik is:
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"

I am not sure about the binding on the Text property, but unless you bind it to the data context, you will no longer need it, because it is unrelated to the problem.

Best wishes,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Darren
Top achievements
Rank 1
answered on 19 May 2009, 02:48 PM
Hi Valeri,

When I try that I get an error that tells me the attachable property is not found.

Thanks,
Darren
0
Accepted
Valeri Hristov
Telerik team
answered on 19 May 2009, 03:29 PM
Hello Darren ,

Did you add the following line:
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"

in your XAML? The final result should look something like this:
<UserControl x:Class="SilverlightApplication1.SilverlightControl3"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
  xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input">
 <Grid x:Name="LayoutRoot" Background="White">
  <telerikInput:RadComboBox telerik:TextSearch.TextPath="Name" ... />
 </Grid>
</UserControl>



Best wishes,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Darren
Top achievements
Rank 1
answered on 19 May 2009, 04:10 PM
Ah!  That worked!  Thank you very much!
Tags
ComboBox
Asked by
Darren
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Darren
Top achievements
Rank 1
Share this question
or