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

GridViewComboBoxColumn binding to collection of strings

1 Answer 163 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ultramods
Top achievements
Rank 1
ultramods asked on 03 Oct 2011, 03:29 PM
Hello,

Is it possible to use the GridViewComboBoxColumn when the grid has been bound to a collection of strings? Using you F1 drivers example if I add a Roles property and bind Roles to the GridView Itemsource I can only get it to work if Roles is an object that I speciify rather than a string.

this works...

public class Driver
    {
        private string countryId;
        private List<Role> roles;
  
        public List<Role> Roles
        {
            get { return roles; }
            set { roles = value; }
        }
  
        public string CountryId
        {
            get { return countryId; }
            set { countryId = value; }
        }
    }
  
    public class Role
    {
        private string id;
  
        public string Id
        {
            get { return id; }
            set { id = value; }
        }
    }

 

<telerik:RadGridView x:Name="radGridView2" ItemsSource="{Binding SelectedDriver.Roles}"
                            AutoGenerateColumns="False">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewComboBoxColumn DataMemberBinding="{Binding Id}"
                                       UniqueName="Role"
                                       SelectedValueMemberPath="Id"
                                       DisplayMemberPath="Id" />
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

this doesn't.....

public class Driver
    {
        private string countryId;
        private List<string> roles;
  
        public List<string> Roles
        {
            get { return roles; }
            set { roles = value; }
        }
  
        public string CountryId
        {
            get { return countryId; }
            set { countryId = value; }
        }
    }

<telerik:RadGridView x:Name="radGridView2" ItemsSource="{Binding SelectedDriver.Roles}"
                            AutoGenerateColumns="False">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewComboBoxColumn DataMemberBinding="{Binding}"
                                       UniqueName="Role"
                                       SelectedValueMemberPath=""
                                       DisplayMemberPath="" />
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

  

If possible I would like to keep roles as a collection of strings because in the actual scenario that I am trying to use this I am binding to ria services User object IEnumerable<string> Roles property.

Thank you in advance for any help.

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 03 Oct 2011, 03:56 PM
Hello,

Firstly, I would recommend you to run through our demo and take a look at some of the approaches for binding GridViewComboBoxColumn.  
The reason the first method works is that all the bindings are set correctly and there is a connection between the source of the column and the source of the grid - the Id properties. Thus once you select an item from the drop-down, the grid will be notified and will update the underlying property (the one you set for the DataMemberBinding of GridViewComboBoxColumn).

Kind regards,
Maya
the Telerik team

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

Tags
GridView
Asked by
ultramods
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or