2
votes

I'm re-writting a .Net WinForm app in WPF.

I need to reproduce a ListView control that has 3 columns.

  • The 1st column is just text.
  • The 2nd column can be an image, a button, or empty.
  • The 3rd column can contain TextBox, ComboBox, DateTimePicker, NumericUpDown, or a CheckBox!

This listview refreshes it's contents (including the types of controls) depending on what has been selected above.

ListView screenshot

Unfortunately I'm new to WPF. I've been researching WPF ListView's and the binding process. But my gut reaction is that this is not a binding scenario (although I'm happy to be proved wrong).

So my questions are can the WPF ListView display different control types per row? If so, how?

Many thanks, Matt.

3

3 Answers

2
votes

Maybe will be useful to someone.

I think DataTemplateSelector can be used in this case. You should define your own selector
inherited from the class DataTemplateSelector and put there the logic what template to use based on the item. Then set it as ItemTemplateSelecto for ListView.

The detail information about DataTemplateSelector can be read from here

0
votes

Take a look at the GridView or a DataGrid. You'll need to manually specify your columns types instead of relying on auto-generated columns

0
votes

Here is a TextBlock and CheckBox

    <ListView.View>
            <GridView AllowsColumnReorder="False" x:Name="gvWFbatches">
                <GridViewColumn Width="Auto">
                    <GridViewColumnHeader Content="Batch"/>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock TextWrapping="NoWrap"  Text="{Binding Path=BatchName, Mode=OneWay}" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Width="Auto">
                    <GridViewColumnHeader Content="QC"/>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox  IsChecked="{Binding Path=IncQC, Mode=OneWay}"  IsHitTestVisible="False" Focusable="False"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>