Determine if RowDetails is expanded or not

Hi.

Using C# and WPF, I am double clicking my DataGrid row and expanding the details view on double click like below.

 Private void data_sessions_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var rowIdx = data_sessions.SelectedIndex;
 this.data_sessions.ExpandDetailsViewAt(rowIdx);
}

Now this works fine. But if I want to reverse it so double click will close if open? I cant seem to find a way to reference that like I did in the standard WPF Datagrid like so : 

DataGridRow row = ItemsControl.ContainerFromElement((DataGrid)sender, e.OriginalSource as DependencyObject) as DataGridRow;

  if (row != null)

{

if (row.DetailsVisibility == Visibility.Collapsed)
row.DetailsVisibility = Visibility.Visible; 

else

row.DetailsVisibility = Visibility.Collapsed;

 }



3 Replies

SP Sreemon Premkumar Muthukrishnan Syncfusion Team October 22, 2024 07:59 AM UTC

Hi Peter,


Your requirement to expand and collapse the DetailsViewDataGrid based on its current state can be achieved by calling the ExpandDetailsViewAt method to expand the DetailsView, and the CollapseDetailsViewAt method to collapse it, by passing the record index. You can determine whether to expand or collapse using the RecordEntry.IsExpanded property. Please find the code snippet below.

Code snippet:

dataGrid.CellDoubleTapped += DataGrid_CellDoubleTapped;

private void DataGrid_CellDoubleTapped(object sender, Syncfusion.UI.Xaml.Grid.GridCellDoubleTappedEventArgs e)

{

    var RecordIndex = dataGrid.ResolveToRecordIndex(e.RowColumnIndex.RowIndex);


    if (this.dataGrid.View.Records[RecordIndex].IsExpanded)

        dataGrid.CollapseDetailsViewAt(RecordIndex);

    else

        dataGrid.ExpandDetailsViewAt(RecordIndex);

}


We have prepared a sample based on your requirement. Please find it in the attachment.


Regards,
Sreemon Premkumar M.


Attachment: WPF_SfDataGrid_MasterDetailsView_e60101a5.zip


PE Peter November 11, 2024 04:38 AM UTC

I do have to apologies; I forgot to reply and say that it worked and thank you very much for your time. It was very much appreciated.


Once again, thankyou.

Rgards
PEter



SP Sreemon Premkumar Muthukrishnan Syncfusion Team November 11, 2024 05:11 AM UTC

Hi Peter,


We hope that your query has been resolved with our proposed solution. Please get back to us if you need further assistance. We are happy to help you.


Regards,
Sreemon Premkumar M.


Loader.
Up arrow icon