I have a DataGrid and would like to hide certain rows in the DataGrid based on what row index they are. An example of what i mean is that if I have a DataGrid with rows:
Mike //Index 0
Steve //Index 1
Smith //Index 2
Greg //Index 3
Jake //Index 4
and I want to hide all names that start with S, is there a way to do something like
dataGrid1.row[1].Hide;
dataGrid1.row[2].Hide;
or something like
dataGrid1.row[1].Visibility = Visibility.Collapsed;
dataGrid1.row[2].Visibility = Visibility.Collapsed;
I do not want to change anything really within my XAML I want to strictly be able to hide a row within my WPF code.
I've seen some really long multiple method ways but is there a way to do this, similarly to
dataGrid1.Columns[1].Visibility = Visibility.Collapsed;
where you can easily hide a column?
Thanks, iato
Edit: What I was looking for was an addition to the potential duplicate question.
var row = (DataGridRow)dg.ItemContainerGenerator.ContainerFromIndex(index);
row.Visibility = Visibility.Collapsed;
was my final solution :)