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

Overriding items source of SfDataGrid.

Hi,
I am trying to override the metadata of SfDataGrid with following code:
public class AdvancedGrid : SfDataGrid
…..
ItemsSourceProperty.OverrideMetadata(typeof(AdvancedGrid), new FrameworkPropertyMetadata(OnItemsSourceChanged));
….
private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is AdvancedGrid grid)
{
grid.HandleItemsSourceChanged(e.OldValue, e.NewValue);
}
}
Please note I have triedPropertyMetadata and UIPropertyMetadata too for passing in metadata details.
Everytime I am ending in exception:
{"Metadata override and base metadata must be of the same type or derived type."}

1 Reply

SP Shobika Palani Syncfusion Team November 13, 2018 12:21 PM UTC

Hi Vasudeva 
 
We have analyzed your query to override metadata of SfDataGrid from our end. We have used GridPropertyMetadata type in our source for ItemsSourceProperty. Because of this only exception raises. So you can resolve this exception by using GridPropertyMetadata instead of FrameworkPropertyMetadata,. Please refer below code snippet  
 
public class CustomSfDataGrid : SfDataGrid 
    { 
        public CustomSfDataGrid() 
        { 
            ItemsSourceProperty.OverrideMetadata(typeof(CustomSfDataGrid), new GridPropertyMetadata(null, OnItemsSourceChanged)); 
        } 
 
        public static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
        { 
            //You can write your own code here. 
        } 
    } 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Shobika. 


Loader.
Up arrow icon