GridViewComboBoxColumn binding to collection of strings

2 posts, 0 answers
  1. ultramods
    ultramods avatar
    18 posts
    Member since:
    Sep 2009

    Posted 03 Oct 2011 Link to this post

    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.

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 03 Oct 2011 Link to this post

    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 >>

Back to Top