How to hide DataGrid row?

Shirase 81 Reputation points
2021-06-24T10:45:48.567+00:00

Hi all,

I want to ask you, how can I hide/show a DataGrid row? Something like

var row = dtgClients.Items[2];
row.Visibility = Visibility.Hide;

or other way, but programatically (.cs), not via xaml
Thanks

C#/WPF/DataGrid

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,853 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,411 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Muthukrishnan Ramasamy 1 Reputation point
    2021-06-24T18:27:28.233+00:00

    You have to remove the item from the Item Source

    0 comments No comments

  2. Muthukrishnan Ramasamy 1 Reputation point
    2021-06-24T18:29:20.52+00:00

    Or you can use the below Style

    <DataGrid.RowStyle>
    <Style TargetType="{x:Type DataGridRow}">
    <Style.Triggers>
    <DataTrigger Binding="{Binding IsVisible}" Value="True">
    <Setter Property="Visibility" Value="Collapsed"/>
    </DataTrigger>
    </Style.Triggers>
    </Style>
    </DataGrid.RowStyle>

    Where IsVisible is a property in source

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.