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

Binding ItemsSource to a simple ObservableCollection<string>

hello,
I would like to bind my datagrid to a simple ObservableCollection<string> to have a basic support of automatic insertion/deletion of strings in a list.
The following is the code I used.

XAML:
<sfGrid:SfDataGrid AddNewRowPosition="Bottom"
                   AllowDeleting="True"
                   AllowEditing="True"
                   AutoGenerateColumns="True"
                   ItemsSource="{x:Bind StringList}" />
Code Behind:
public ObservableCollection<string> StringList => new ObservableCollection<string> { "abc""def""123"};
Result:

not really what I was expecting...
How can I bind to a simple ObservableCollection<string> without DataGrid to try to get String Properties and display them, but actually use the basic string?

4 Replies

SP Sowndaiyan Paulpandi Syncfusion Team September 21, 2016 04:18 PM UTC

Hi Luca

Thanks for contacting Syncfusion Support.

In SfDataGrid, you can display the string properties using the GridTemplateColumn when the SfDataGrid is bound to string collection. But it is not possible to add new records using AddNewRow and also it is not possible to edit the records. However you can able to add the item from code behind and also you can delete the records by setting the SfDataGrid.AllowDeleting property as true. We have prepared  a sample as per your requirement and you can download the sample from the below location,

Sample : http://www.syncfusion.com/downloads/support/forum/126058/ze/UWP-661448407


Regards,
Sowndaiyan



LS Luca Spolidoro September 23, 2016 01:09 AM UTC

Thanks Sowndaiyan,
with your suggestion I was able to implement the simple string databinding.
I had to add a textbox to support Add new item, but it's fine (deletion fortunately it's supported)


SV Srinivasan Vasu Syncfusion Team September 23, 2016 10:01 AM UTC

Hi Luca, 

Thanks for your update. 
  
Please  
Regards, 
Srinivasan 



SV Srinivasan Vasu Syncfusion Team September 23, 2016 10:06 AM UTC

Hi Luca, 
  
Please let us know if you need further assistance on this. 
  
Regards, 
Srinivasan 


Loader.
Live Chat Icon For mobile
Up arrow icon