We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

DisplayMemberPath with Multiple Columns not working...

Thread ID:

Created:

Updated:

Platform:

Replies:

141740 Jan 1,2019 10:52 PM UTC Jan 8,2019 05:19 AM UTC Xamarin.Forms 1
loading
Tags: SfPicker
Vinnivan
Asked On January 1, 2019 10:52 PM UTC

Please advise on how to configure DisplayMemberPath properly when using multiple columns. 

I have a list of Category which each contain sub Categories. I want the picker to display the value of the property "Name" in each column. 

class Category
{
     int Id { get;}
     string Name {get; }
     List<Category> SubCategories { get}
}

List<Category> categories = service.GetCategories();
ObservableCollection<List<Category>> ItemsSource; <-- This is databound to the sfPicker

** Note: this works if I don't set DisplayMemberPath - I see two columns but the type name instead of  Name property
ItemsSource.Add(categories);
ItemsSource.Add(categories.First().SubCategories);

** So the problem is with DisplayMemberPath ** 

1. If I set it to "Name" - this doesn't work as which column/collection is it referring to? The Categories or SubCategories? 
- The Xaml binding fails with error shown below
2. If I bind it to a List<string> { "Name", "Name" } -> The Xaml binding fails with the error shown below
3. If I set DisplayMemberPath in the code behind - it just doesn't do anything and I just see the "TypeName" as the string to select in the picker

Here is the Xaml error I'm getting:
Error  Position 31:18. No property, bindable property, or event found for 'DisplayMemberPath', or mismatching type between value and property.

Thanks in advance!










Dhanasekar R [Syncfusion]
Replied On January 8, 2019 05:19 AM UTC

Hi John, 
 
We have validated your scenario "DisplayMemberPath is not working correctly when using multicolumn picker". We have created the sample based on your requirement in which we have added the Name collection to the DisplayMemberPath and the collection gets updated in the picker column. Please use the below code snippet while setting the DisplayMemberPath. 
 
ObservableCollection<object> collection = new ObservableCollection<object>();
            collection.Add(ViewModel.Countries);

            List<Category> SubCollection = new List<Category>();
            foreach (var item in ViewModel.Countries)
            {
                SubCollection.AddRange(item.SubCategories);
            }
            collection.Add(SubCollection);
            picker.ItemsSource = collection;
            picker.DisplayMemberPath = new ObservableCollection<object>() { "Name", "Name" }; 
 
 
Please refer the below screenshot and sample for your reference.  
 
Screenshot 
 
 
 
 
Please try our above sample and let us know if any further clarifications on this. 
 
Regards, 
Dhanasekar 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;