Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,38 @@
# How to hide the detailsview expander icon based on child records count in winui datagrid?
This example describes how to hide the detailsview expander icon based on child records count in winui datagrid.
# How to hide the detailsview expander icon based on child records count in WinUI DataGrid

This example describes how to hide the detailsview expander icon based on child records count in [WinUI DataGrid](https://www.syncfusion.com/winui-controls/datagrid) (SfDataGrid).

By default, the state of expander icon is visible for all the data rows in parent DataGrid even if its `RelationalColumn` property has an empty collection or null.

You can customize hiding the details view expander icon by handling the `SfDataGrid.QueryDetailsViewExpanderState` event. This event occurs when expander icon is changed on expanding or collapsing the details view. You can hide the expander icon by setting the `ExpanderVisibility` property to `false` in the `SfDataGrid.QueryDetailsViewExpanderState` event based on condition.

``` csharp
dataGrid.DetailsViewExpanding += DataGrid_DetailsViewExpanding;
dataGrid.QueryDetailsViewExpanderState += DataGrid_QueryDetailsViewExpanderState;

private void DataGrid_DetailsViewExpanding(object sender, GridDetailsViewExpandingEventArgs e)
{
var employeeInfo = e.Record as Employee;
if (employeeInfo != null)
{
if (employeeInfo.Sales.Count == 0)
e.Cancel = true;
}
}

private void DataGrid_QueryDetailsViewExpanderState(object sender, QueryDetailsViewExpanderStateEventArgs e)
{
var employeeInfo = e.Record as Employee;
if (employeeInfo != null)
{
if (employeeInfo.Sales.Count == 0)
{
e.ExpanderVisibility = false;
}
}
}
```

The following screenshot illustrates hiding expander icon state based on child items count.

![hide the detailsview expander](hide_the_detailsview_expander_icon.png)
Binary file added hide_the_detailsview_expander_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.