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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Issues binding to ICustomTypeDescriptor

Thread ID:

Created:

Updated:

Platform:

Replies:

149714 Dec 6,2019 10:53 AM UTC Dec 10,2019 10:06 AM UTC Xamarin.Forms 3
loading
Tags: SfDataGrid
Jaime Lopez
Asked On December 6, 2019 10:55 AM UTC

I have a class that implements ICustomTypeDescriptor and has a mix of normal properties and properties created at runtime. The normal properties all bind fine but the properties that implement their own PropertyDescriptor are not being bound. I am wondering if SfDataGrid supports this scenario and if it does could you make a sample.

I am on version 17.3.0.29 of Xamarin.Forms for Syncfusion.

Balasubramani Sundaram [Syncfusion]
Replied On December 9, 2019 01:21 PM UTC

Hi Jaime,  
 
Thank you for contacting Syncfusion support.   
 
Based on your provided details, we have prepared a sample with ICustomTypeDescriptor property and normal CLR property is bounded in the SfDataGrid and its working as we expected. Please refer the below sample for more details.  
 
 
Please check the sample and let us know if you still facing the same issue? If not, please modify the sample based on your scenario and revert us with the more details, so that it will be helpful for us to check on it and provide you the solution at the earliest.    
   
Regards,   
Balasubramani Sundaram   


Jaime Lopez
Replied On December 9, 2019 02:53 PM UTC

I took a look at the sample and made some changes to fit the requirements. I am trying to add columns and have them bind to properties that are created at runtime. If you look at the changes in Mainpage.xaml.cs you will see me create the columns for the grid at runtime. I also modified CustomTypeDescriptorInfo.cs to have a mix of normal CLR properties and properties that are created through ICustomTypeDescriptor.

The columns are created but the data is not bound.

In Repositoy.cs I am setting the dynamic properties.

Attachment: DataGridDemo1938352298__Modified_40919bb8.zip

Balasubramani Sundaram [Syncfusion]
Replied On December 10, 2019 10:06 AM UTC

Hi Jaime,  
 
Thanks for the update.     
 
SfDataGrid is a data bound grid, the columns and data will bound based on the under-collection property. The bounded property must present in the underline collection else it will create a column, but data will not bound in respective grid cell. So, in this case other than the GridUnboundColumn, for remaining column type the property must to present in the Underline collection. By using the UnboundColumn you can achieve your requirement for more details please refer the UG link. 
 
Please refer the below code snippet and sample, 
 
Code Snippet [C#] 
 
[MainPage.Xaml.cs] 
 
public partial class MainPage : ContentPage 
{ 
    public MainPage() 
    { 
        .......... 
        .......... 
        this.myGrid.QueryUnboundColumnValue += MyGrid_QueryUnboundColumnValue; 
    } 
 
    private void MyGrid_QueryUnboundColumnValue(object sender, GridUnboundColumnEventArgs e) 
    { 
        if (e.UnboundAction == UnboundActions.QueryData) 
        { 
            Dictionary<string, CellData> rowData = e.Record.GetType().GetField("_data", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(e.Record) as Dictionary<string, CellData>; 
            var cellData = rowData.FirstOrDefault(x => x.Key.Equals(e.Column.MappingName)).Value as Cel 
            e.Value = cellData.Value; 
        } 
    } 
 
    private void ViewModelOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) 
    { 
        ....... 
        ....... 
 
        myGrid.Columns.Clear(); 
        myGrid.Columns.Add(orderIdCol); 
        myGrid.Columns.Add(employeeCol); 
 
        foreach (var key in keys) 
        { 
            GridUnboundColumn column = new GridUnboundColumn(); 
            column.Expression = key; 
            column.MappingName = key; 
            column.HeaderText = key; 
            column.Width = 100; 
            myGrid.Columns.Add(column); 
        } 
 
        ....... 
        ....... 
    } 
} 
 
 
 
 
We hope this helps. Please let us know, if you need any further assistance. 
 
Regards,
Balasubramani Sundaram. 


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

Live Chat Icon For mobile
Live Chat Icon