Multiselect mode not working for listview control containing a Gridview
-
Hi, i am trying to make a WPF listview control that contains a gridview. The problem is when i run the application, at one time user can select just 1 row of the grid. If user selects another row, the previous row selected is un-selected automatically i have tried using cntrl+ mouseclick still i can not select multiple grid view rows. What exactly i want to do is, i would like to display gridview's coloumn(0) value of all the selected rows(concatinating each value) in the some textbox. Can anyone Please help? My code is: <DataTemplate x:Key="FirstCell"> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}" > </CheckBox> </StackPanel> </DataTemplate> <ListView ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" Name="ListView1" Margin="218,83,25,88" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionChanged="ListView1_SelectionChanged" SelectionMode="Multiple"> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> <EventSetter Event="GotFocus" Handler="Item_GotFocus" /> </Style> </ListView.ItemContainerStyle> <ListView.View > <GridView x:Name="Grid1" > <GridViewColumn Header="Code" Width="70" > <GridViewColumn.CellTemplate> <DataTemplate> <TextBox Text="{Binding Path=Code}" Margin="-6,0,-6,0" x:Name="Codename"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="Discription" Width="70" > <GridViewColumn.CellTemplate> <DataTemplate >
-
Hi, i am trying to make a WPF listview control that contains a gridview. The problem is when i run the application, at one time user can select just 1 row of the grid. If user selects another row, the previous row selected is un-selected automatically i have tried using cntrl+ mouseclick still i can not select multiple grid view rows. What exactly i want to do is, i would like to display gridview's coloumn(0) value of all the selected rows(concatinating each value) in the some textbox. Can anyone Please help? My code is: <DataTemplate x:Key="FirstCell"> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}" > </CheckBox> </StackPanel> </DataTemplate> <ListView ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" Name="ListView1" Margin="218,83,25,88" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionChanged="ListView1_SelectionChanged" SelectionMode="Multiple"> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> <EventSetter Event="GotFocus" Handler="Item_GotFocus" /> </Style> </ListView.ItemContainerStyle> <ListView.View > <GridView x:Name="Grid1" > <GridViewColumn Header="Code" Width="70" > <GridViewColumn.CellTemplate> <DataTemplate> <TextBox Text="{Binding Path=Code}" Margin="-6,0,-6,0" x:Name="Codename"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="Discription" Width="70" > <GridViewColumn.CellTemplate> <DataTemplate >
SR81 wrote:
The problem is when i run the application, at one time user can select just 1 row of the grid. If user selects another row, the previous row selected is un-selected automatically
Your code works for me. Multiple selections work - no CTRL key necessary. Only change I made is fixed the broken FirstCell data template (it wouldn't compile so I removed the binding from the checkbox) and removed all event handlers since you didn't provide the code.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Hi, i am trying to make a WPF listview control that contains a gridview. The problem is when i run the application, at one time user can select just 1 row of the grid. If user selects another row, the previous row selected is un-selected automatically i have tried using cntrl+ mouseclick still i can not select multiple grid view rows. What exactly i want to do is, i would like to display gridview's coloumn(0) value of all the selected rows(concatinating each value) in the some textbox. Can anyone Please help? My code is: <DataTemplate x:Key="FirstCell"> <StackPanel Orientation="Horizontal"> <CheckBox IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}}" > </CheckBox> </StackPanel> </DataTemplate> <ListView ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" Name="ListView1" Margin="218,83,25,88" ScrollViewer.CanContentScroll="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionChanged="ListView1_SelectionChanged" SelectionMode="Multiple"> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="HorizontalContentAlignment" Value="Stretch" /> <EventSetter Event="GotFocus" Handler="Item_GotFocus" /> </Style> </ListView.ItemContainerStyle> <ListView.View > <GridView x:Name="Grid1" > <GridViewColumn Header="Code" Width="70" > <GridViewColumn.CellTemplate> <DataTemplate> <TextBox Text="{Binding Path=Code}" Margin="-6,0,-6,0" x:Name="Codename"/> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> <GridViewColumn Header="Discription" Width="70" > <GridViewColumn.CellTemplate> <DataTemplate >
Always use
SelectionMode="Extended"
and not SelectionMode="Multiple" Try this and vote me :)
Niladri Biswas