vendredi 26 août 2016

Uncheck all other checkboxes if one is checked

I've used a XAML ListView and one of the columns in the Listview is a checkbox.when the data is bound to the ListView it creates multiple rows with on of the column as a checkbox. The problem I'm facing I want the user to be able to select only one checkbox whereas right now he can select multiple.All other check boxes should get unchecked when user selects one.

This is the XAML part.

<ListView  ScrollViewer.VerticalScrollBarVisibility="Auto"  Name="ClientList" Width="Auto" Height="Auto" BorderThickness="0.5" BorderBrush="#cccccc" IsSynchronizedWithCurrentItem="True" HorizontalAlignment="Stretch" Margin="20,10,60,0" >

                    <ListView.ItemContainerStyle>

                        <Style TargetType="ListViewItem">
                            <Setter Property="Focusable" Value="false"/>
                            <Setter Property="Foreground" Value="Black"/>
                            <Setter Property="Height" Value="30"/>
                        </Style>
                    </ListView.ItemContainerStyle>

                    <ListView.View>
                        <GridView  ColumnHeaderContainerStyle="{StaticResource GridViewColumnHeaderStyle1}">
                            <GridViewColumn Header="Client Name " x:Name="clienteName" DisplayMemberBinding="{Binding ClientName}"  Width="390"  />
                            <GridViewColumn Header="Client Code " x:Name="ClienteCode" DisplayMemberBinding="{Binding ClientCode}"  Width="195" />
                            <GridViewColumn Header="Select" Width="57">
                                <GridViewColumn.CellTemplate>
                                    <DataTemplate >
                                        <Grid >
                                            <CheckBox DataContext="{Binding ClientCode}"  Click="CheckBox_Click" TouchDown="CheckBox_TouchDown"/>
                                        </Grid>
                                    </DataTemplate>
                                </GridViewColumn.CellTemplate>
                            </GridViewColumn>

                        </GridView>
                    </ListView.View>
</ListView>

CS used for binding the data to the ListView

List<Client> list = new List<Client>();
ClientList.Items.Clear();
list = getListFromDT(dt);

foreach (Client pr in list)
{
   ClientList.Items.Add(pr);
}  




Aucun commentaire:

Enregistrer un commentaire