Articles in this section
Category / Section

How to get the CurrentCell for DetailsViewDatagrid at runtime in WPF DataGrid?

3 mins read

You can get the CurrentCell of DetailsViewDataGrid by using the SelectedDetailsViewGrid property.

 

C#

 

var currentCell = this.dataGrid.SelectedDetailsViewGrid.SelectionController.CurrentCellManager.CurrentCell;

 

In another way, you can use CurrentCellActivated event to get CurrentCell when it gets changed.

 

When AutoGeneratingRelation property as false, you wire event directly from GridViewDefinition.DataGrid to get the current cell by handling CurrentCellActivated event.

XAML

<Syncfusion:SfDataGrid x:Name="datagrid"
                        AllowEditing="True"
                        AutoGenerateRelations="False"
                        ItemsSource="{Binding OrderInfoCollection}"
                        NavigationMode="Cell">
    <Syncfusion:SfDataGrid.DetailsViewDefinition>
    <Syncfusion:GridViewDefinition RelationalColumn="ProductDetails">
        <Syncfusion:GridViewDefinition.DataGrid>
            <Syncfusion:SfDataGrid x:Name="detailsDataGrid"
                                    AllowEditing="True"
                                    AllowSorting="False" />
        </Syncfusion:GridViewDefinition.DataGrid>
    </Syncfusion:GridViewDefinition>
</Syncfusion:SfDataGrid.DetailsViewDefinition>
</Syncfusion:SfDataGrid>

 

C#

this.detailsDataGrid.CurrentCellActivated +=detailsDataGrid_CurrentCellActivated;
 
private void detailsDataGrid_CurrentCellActivated(object sender, CurrentCellActivatedEventArgs args)
{
    if (args.OriginalSender is DetailsViewDataGrid)
    {
        var detailsViewDataGrid = args.OriginalSender as DetailsViewDataGrid;
        var currentCell = detailsViewDataGrid.SelectionController.CurrentCellManager.CurrentCell;
    }
}

 

When AutoGeneratingRelation property as true, you can get the GridViewDefinition.DataGrid in the AutoGeneratingRelations event handler to wire the CurrentCellActivated event.

C#

this.datagrid.AutoGeneratingRelations += datagrid_AutoGeneratingRelations;
 
void datagrid_AutoGeneratingRelations(object sender, AutoGeneratingRelationsArgs e)
{
    e.GridViewDefinition.DataGrid.CurrentCellActivated += DataGrid_CurrentCellActivated;
}
 
void DataGrid_CurrentCellActivated(object sender, CurrentCellActivatedEventArgs args)
{
    if (args.OriginalSender is DetailsViewDataGrid)
    {
        var detailsViewDataGrid = args.OriginalSender as DetailsViewDataGrid;
        var currentCell = detailsViewDataGrid.SelectionController.CurrentCellManager.CurrentCell;
    }
}

 

Sample Links:

WPF

UWP

 

 

Conclusion

I hope you enjoyed learning about how to get the CurrentCell for DetailsViewDatagrid at runtime in WPF DtaGrid.


You can refer to our WPF DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF DataGrid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied