Takeshi Tokugawa YD
Takeshi Tokugawa YD

Reputation: 923

WPF&MVVM: Add controls to auto-generated List View

I want to create the List View like this:

enter image description here

(Although the List View already has multi-select function and don't need the checkboxes, I want to add them for low-experience user who don't know what if to hold Shift key it's possible to select multiple items.)

Currently, my List View includes only ID and Full Name columns; the data displays by binding created according MVVC concept.

<ListView Name="DataTable" ItemsSource="{Binding Path=people}">
    <ListView.View>
        <GridView>
            <GridViewColumn Width="50px">
                <!-- This is column for checkboxes but it don't should be in header  -->
            </GridViewColumn>  
            <GridViewColumn Header="ID" 
                            DisplayMemberBinding="{Binding PersonID, UpdateSourceTrigger=PropertyChanged}">
            </GridViewColumn>
            <GridViewColumn Header="FullName" 
                            DisplayMemberBinding="{Binding FullName, UpdateSourceTrigger=PropertyChanged}" />
            <GridViewColumn Width="50px">
                <!-- This is column for "Edit" buttons but it don't should be in header  -->
            </GridViewColumn>  
            <GridViewColumn Width="50px">
                <!-- This is column for "Delete" buttons but it don't should be in header  -->
            </GridViewColumn>  
        </GridView>
    </ListView.View>
</ListView>

How I can add the checkboxes and buttons in every not-header row?

Upvotes: 0

Views: 71

Answers (1)

Renshaw
Renshaw

Reputation: 1155

You should declare a CellTemplate with a CheckBox:

<GridViewColumn Width="50px">
    <GridViewColumn.CellTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding MyProperty}"/>
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

Upvotes: 1

Related Questions