-1

I have listview with 10 GridViewColumns, each column should be visible at runtime based on a condition, of course the column can be collapsed by setting the width to 0. but how to do this programaticaly let say if P[1].TestResult = "NA" then the column should collapsed.

<GridViewColumn Width="50" Header="P-1">
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <TextBlock x:Name="P1" Text="{Binding P[1].TestResult}" TextAlignment="Center" FontSize="20" Style="{StaticResource CellStyle}" />
        </DataTemplate>

    </GridViewColumn.CellTemplate>
</GridViewColumn>

<GridViewColumn Width="50" Header="P-2">
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <TextBlock x:Name="P2" Text="{Binding P[2].TestResult}" TextAlignment="Center" FontSize="20"  Style="{StaticResource CellStyle}"/>
        </DataTemplate>

    </GridViewColumn.CellTemplate>
</GridViewColumn>

<!-- ... -->
thatguy
  • 21,059
  • 6
  • 30
  • 40

1 Answers1

0

You say that if TestResult of any item in a column is NA, it should be hidden. You could expose a computed bool property that implements the condition. You could probably use Linq's Any method for this, but I cannot assume your types, so you have to implement it yourself.

public bool IsAnyP1TestResultNotAvailable => /* ...check if any test result is NA */.

Then you could use one of the numerous converters from C#/WPF: Make a GridViewColumn Visible=false? to hide the specific column by binding to this property. Whenever TestResult changes (e.g. in its setter), you could raise the PropertyChanged event for the computed property to update the bindings in the user interface.

thatguy
  • 21,059
  • 6
  • 30
  • 40