vendredi 3 février 2017

Wpf DataGrid hide rows when checkbox is true and bound data is true

I want to disable visibility(collapse) of certain rows when a checkbox is checked and the bound data that is on that row matches certain criteria. for example(pseudo code):

    If(IsHideEnabledChecked && Row.Data.Enabled)
       Row.Visibility = Collapsed

I have created the datagrid(s) pro-grammatically due to the nature of the project i am working on, the number of datagrids need to match the number of objects in my collection. Normally in a non wpf world you would loop through the grids and change the row on condition:

public void HideEnabled(object sender, RoutedEventArgs)
   Foreach(DataGrid grid in DataGrids)
   {
     Foreach(DataGridRow row in grid)
     {
       if(row[0].Value == True)
           row.Visibile = false
     }
   }

My question is, how do i hide the rows after the checkbox is selected? and how would this be checked against the values on the current row? Can this all be done in c#? I have looked around and can see that dataTriggers can be used to bind a control to a column and datatype but that would not include checking against the bound data(the property "enabled")

Any help would be much appreciated :)

Aucun commentaire:

Enregistrer un commentaire