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. Image for the cookie policy date

DisplayMemberPath not working with Arrays

Hi,

I want to add a list of classes at the DataSource and the class has a string[] property with name "Entries".
For example in the SfDataGrid I add as MappingName = "Entries[0]" and the Cell references to  any_object.Entries[0].

I hoped that it works simliar to DisplayMemberPath but I got not the same successful result.

Does anybody has a hint?

My code:

...

_comboBox = new SfComboBox();


_comboBox.IsEditableMode = false;

_comboBox.MaximumDropDownHeight = 200;

_comboBox.HeightRequest = 40;

Entries = new ObservableCollection<SelectionViewEntry>();


_comboBox.DataSource = this.Entries;

_comboBox.DisplayMemberPath = "Entries[0]";


...


public class SelectionViewEntry

{

public string[] Entries { get; set; }

}



3 Replies

PA Paul Anderson S Syncfusion Team November 21, 2018 12:07 PM UTC

Hi Thomas Loidolt, 
 
Greetings from Syncfusion. 
 
We checked the given code snippet and when using String [] type for the data source it returns only the array object. We have also tested the same String [] type data with the ListView control and it also returned only the array object. We have prepared a sample on how to use a collection of a custom class and display the desired property using DisplayMemberPath. Please find the sample from the below link. 
 
 
For more information about using “DisplayMemberPath” property is given below: 
 
 
Please check our sample and let us know if you have any concerns. 
 
Regards, 
Paul Anderson 



TL Thomas Loidolt November 21, 2018 03:40 PM UTC

Hi,

your solution is not working for my requirements but I found another way to solve it:

public class SelectionViewEntry
{
public int ColumnIndex { get; set; }
public string Entry { get => Entries[ColumnIndex]; set => Entries[ColumnIndex] = value; }
public string[] Entries { get; set; }
}

And this is a working example of SfDataGrid and MappingName:

_dataGrid.Columns.Add(new GridTextColumn() { MappingName = "Features[" + i.ToString() + "]", HeaderText = item.Value.Value, TextAlignment = item.Value.HorizontalAlignment, FontAttribute = FontAttributes.Bold });

BR,Thomas


PA Paul Anderson S Syncfusion Team November 22, 2018 04:23 AM UTC

Hi Thomas, 
  
Thanks for the update. We are glad that you have achieved your requirement. Please get in touch if you required further assistance. 
  
Regards, 
Paul Anderson 


Loader.
Up arrow icon