Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Multiselect mode not working for listview control containing a Gridview

Multiselect mode not working for listview control containing a Gridview

Scheduled Pinned Locked Moved WPF
wpfhelpcsharpcsswcf
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    S Rajput
    wrote on last edited by
    #1

    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 >

    M N 2 Replies Last reply
    0
    • S S Rajput

      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 >

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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:

      1 Reply Last reply
      0
      • S S Rajput

        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 >

        N Offline
        N Offline
        Niladri_Biswas
        wrote on last edited by
        #3

        Always use

        SelectionMode="Extended"

        and not SelectionMode="Multiple" Try this and vote me :)

        Niladri Biswas

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups