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

Multi column in combobox with IsComboBoxEditable="True" is Error

2 Answers 54 Views
GridView
This is a migrated thread and some comments may be shown as answers.
tuan
Top achievements
Rank 1
tuan asked on 18 Apr 2011, 11:48 AM
Hi, I use GridView with combobox (multi columns in combobox) and IsComboBoxEditable="True" is display error (errorgridview.png)

My code axml follow as:
<telerik:RadGridView Name="grvData" AutoGenerateColumns="False" >
        <telerik:RadGridView.Columns>
            <telerik:GridViewComboBoxColumn Header="Country" 
                        UniqueName="Country"
                        DataMemberBinding="{Binding Code}" 
                        DisplayMemberPath="Name" 
                        SelectedValueMemberPath="Code" 
                        Width="150"  IsComboBoxEditable="True" 
                        telerik:TextSearch.TextPath="Code">
                <telerik:GridViewComboBoxColumn.EditorStyle>
                    <Style TargetType="telerik:RadComboBox">
                        <Setter Property="SelectionBoxTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Code}" Margin="5">
                                    </TextBlock>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="ItemTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="100"></ColumnDefinition>
                                            <ColumnDefinition Width="200"></ColumnDefinition>
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Text="{Binding Code}" Margin="5" ></TextBlock>
                                        <TextBlock Text="{Binding Name}" Margin="5" 
                                                   Grid.Column="1" 
                                                   HorizontalAlignment="Left"></TextBlock>
                                    </Grid>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </telerik:GridViewComboBoxColumn.EditorStyle>
            </telerik:GridViewComboBoxColumn
        </telerik:RadGridView.Columns>
</telerik:RadGridView>

and cs:
public partial class MainPage : UserControl
   {
       public MainPage()
       {
           InitializeComponent();            
           List<Country> list1 = new List<Country>();
           list1.Add(new Country() { Code = "eng", Name = "English" });
           list1.Add(new Country() { Code = "vni", Name = "Viet Nam" });
           list1.Add(new Country() { Code = "chi", Name = "China" });
           this.grvData.ItemsSource = list1;
           ((GridViewComboBoxColumn)this.grvData.Columns["Country"]).ItemsSource = list1;
       }
   }
   public class Country
   {
       public string Code { get; set; }
       public string Name { get; set; }
   }

please help me!

Thanks

2 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 18 Apr 2011, 02:08 PM
Hi tuan,

You may override the ToString() method in your Country class:

public class Country
    {
        public string Code{get;set;}
        public string Name{get;set;}
 
        public override string ToString()
        {
            return this.Name;
        }
    }

Thus the editor will not return the whole object, but rather the corresponding value for the Name property.
 

Regards,
Maya
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
Marc Roussel
Top achievements
Rank 2
answered on 29 Apr 2013, 03:39 PM
Mistake.  To delete
Tags
GridView
Asked by
tuan
Top achievements
Rank 1
Answers by
Maya
Telerik team
Marc Roussel
Top achievements
Rank 2
Share this question
or