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

What is the equivalent of AfterRowLoaded event in sfDataGrid.

What are the equivalent of AfterRowLoaded and RowActivated events in sfDataGrid.

I hope at least I will get the answer of this question otherwise, its useless if I get an answer in a week or so.

3 Replies

FP Farjana Parveen Ayubb Syncfusion Team July 4, 2019 08:57 AM UTC

Hi Qasim, 
  
Thank you for contacting Syncfusion Support. 
  
We have analyzed your query. Your requirement to get row added at runtime by using SfDataGrid.View.Records.CollectionChanged event which will fire whenever the underlying collection is changed. Also when row is selected, SfDataGrid.CurrentCellActivating event will be fired. Please refer the below code snippet  
  
public class CustomBehavior : Behavior<SfDataGrid> 
    { 
        protected override void OnAttached() 
        { 
            this.AssociatedObject.Loaded += AssociatedObject_Loaded; 
            this.AssociatedObject.CurrentCellActivating += AssociatedObject_CurrentCellActivating; 
        } 
  
        private void AssociatedObject_CurrentCellActivating(object sender, CurrentCellActivatingEventArgs e) 
        { 
            var rowIndex = e.CurrentRowColumnIndex.RowIndex; 
            var dataRow = AssociatedObject.RowGenerator.Items.FirstOrDefault(row => row.RowIndex == rowIndex) as DataRow; 
            //you can write your own code here. 
        } 
  
        private void AssociatedObject_Loaded(object sender, System.Windows.RoutedEventArgs e) 
        { 
            this.AssociatedObject.View.Records.CollectionChanged += Records_CollectionChanged; 
        } 
  
        private void Records_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) 
        { 
            if (e.Action == NotifyCollectionChangedAction.Add) 
            { 
                var rowIndex =this.AssociatedObject.ResolveToRowIndex(e.NewItems[0]); 
                this.AssociatedObject.ScrollInView(new RowColumnIndex(rowIndex,this.AssociatedObject.GetFirstColumnIndex())); 
                AssociatedObject.Dispatcher.BeginInvoke(DispatcherPriority.Background, 
                    new Action(() => 
                    { 
                        var dataRow = AssociatedObject.RowGenerator.Items.FirstOrDefault(row => row.RowIndex == rowIndex) as DataRow; 
                        //you can write your own code here. 
                    })); 
            } 
        } 
    } 
  
Please find sample for the same from below link and let us know if this helps you,  
 
  
If the above events does not meet your requirement, please let us know your exact requirement on what action you would like to do with SfDataGrid once the row was loaded. If you provide those details only we could know and suggest the exact event for your required action. 
  
Regards, 
Farjana Parveen A 



QR Qasim Raza July 8, 2019 07:15 AM UTC

HI

No this is not what I was looking into. Let me repharase my question.

"When a row in a grid is loaded, in default WPF framework we have an event named "AfterRowLoaded". Which get fires.
this help us to make for example some row level formating.

As per the default description of WPF core framework. it says

AfterRowLoaded occurs after a row is loaded.


Now can you please share the detail of event that is equivalent to this behavior or replica of this even in SyncFusion sfDataGrid along with some example.






SP Shobika Palani Syncfusion Team July 9, 2019 01:56 PM UTC

Hi Qasim, 

Thanks for the update. 

SfDataGrid does not have event equivalent to AfterRowLoaded. On further analyzing your requirement to apply formatting in row level, you can write style targeting VirtualizingCellsControl. Please refer to the below UG links and KB articles to know more details on styling rows 

UG Links: 

KB Links: 

If above articles does not meet your requirement, please let us know your exact requirement on how you want to apply row level formatting in your grid. It will helps us to investigate further and provide earlier prompt solution. 

Regards, 
Shobika. 


Loader.
Live Chat Icon For mobile
Up arrow icon