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

Issues binding to ICustomTypeDescriptor

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.

3 Replies

BS Balasubramani Sundaram Syncfusion Team 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   



JL Jaime Lopez 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


BS Balasubramani Sundaram Syncfusion Team 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. 


Loader.
Live Chat Icon For mobile
Up arrow icon