Access current row or record while in CurrentCellBeginEdit

Hi, I am trying to get the current row object or record in my CurrentCellBeginEdit. Is there a way to do this; specifically when I am in the New Row Addition. I tried to add an attachedproperty to my sfdatagrid as below but it stays null:


    public class CurrentRowAttProp
{
public static void SetCurrentRow(DependencyObject element, object value)
{
if (element is SfDataGrid || element is ListView)
element.SetValue(CurrentRowProperty, value);
else
throw new NotSupportedException("This property can be used only with SfDataGrid");
}
public static object GetCurrentRow(DependencyObject element)
{
return (object)element.GetValue(CurrentRowProperty);
}


public static readonly DependencyProperty CurrentRowProperty =
DependencyProperty.RegisterAttached("CurrentRow", typeof(object), typeof(CurrentRowAttProp), new PropertyMetadata(null, OnCellTapped));
private static void OnCellTapped(DependencyObject d, DependencyPropertyChangedEventArgs args)
{
if (d is SfDataGrid)
{
var sfDataGrid = d as SfDataGrid;
if (sfDataGrid == null)
return;

sfDataGrid.CellTapped += (sender, e) =>
{
CurrentRowAttProp.SetCurrentRow(sfDataGrid, e.Record);
};
}
}
}

1 Reply

MA Mohanram Anbukkarasu Syncfusion Team January 17, 2022 12:57 PM UTC

Hi Moustafa, 

You can get the current row data object in the CurrentCellBeginEdit event by using SfDataGrid.CurrentItem property as shown in the following code example.  

Code example :  

private void DataGrid_CurrentCellBeginEdit(object sender, Syncfusion.UI.Xaml.Grid.CurrentCellBeginEditEventArgs e) 
{ 
    var currentRecord = this.dataGrid.CurrentItem; 
} 


Please have a look at this sample and let us know if you require further assistance from us.  

Regards, 
Mohanram A. 


Loader.
Up arrow icon