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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. ListView Item Selection

ListView Item Selection

Scheduled Pinned Locked Moved C#
questionhelp
5 Posts 2 Posters 1 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.
  • T Offline
    T Offline
    takkung
    wrote on last edited by
    #1

    Hi everybody!! I 've a problem about ListView In my Windows Form Application. I 've created a song playlist editor that use list view to display the songs and I have move up and move down button for move the song up and down in the list view. But when I push the move up or move down button the row selection will disappear because it lost focus. Does anyone know how can I preserve the row selection of list view because it doesn't have SetSelected method like ListBox Control? Thank you and sorry for about my English.

    N 1 Reply Last reply
    0
    • T takkung

      Hi everybody!! I 've a problem about ListView In my Windows Form Application. I 've created a song playlist editor that use list view to display the songs and I have move up and move down button for move the song up and down in the list view. But when I push the move up or move down button the row selection will disappear because it lost focus. Does anyone know how can I preserve the row selection of list view because it doesn't have SetSelected method like ListBox Control? Thank you and sorry for about my English.

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      takkung wrote: Does anyone know how can I preserve the row selection of list view because it doesn't have SetSelected method like ListBox Control? Yep, set the ListView.HideSelection[^] property to false.

      - Nick Parker Microsoft MVP - Visual C#
      My Blog | My Articles

      T 2 Replies Last reply
      0
      • N Nick Parker

        takkung wrote: Does anyone know how can I preserve the row selection of list view because it doesn't have SetSelected method like ListBox Control? Yep, set the ListView.HideSelection[^] property to false.

        - Nick Parker Microsoft MVP - Visual C#
        My Blog | My Articles

        T Offline
        T Offline
        takkung
        wrote on last edited by
        #3

        I already set ListView.HideSelection but I can't presserve highlighting from a selected item. I think when I select an item and I push Move Up button then the listview control need to be repaint the control because the items in the listview control has changed so the highlighting will be disappear. The problem is how can I preserve the highlighting at the item that I 've moved up or moved down so I can continue to move that item up or down again and so on. In Listbox control there 's SetSelected method so it can highlight the moved up/down item but in ListView it doesn't have SetSelected method. this is my code( Move up button click event handler ) int curIndex = this.listSelectedSongs.Items.IndexOf(listSelectedSongs.SelectedItems[0]); ListViewItem aboveTmpItem = (ListViewItem)this.listSelectedSongs.Items[curIndex-1].Clone(); ListViewItem curTmpItem = (ListViewItem)this.listSelectedSongs.Items[curIndex].Clone(); this.listSelectedSongs.Items[curIndex-1] = curTmpItem; this.listSelectedSongs.Items[curIndex] = aboveTmpItem;

        1 Reply Last reply
        0
        • N Nick Parker

          takkung wrote: Does anyone know how can I preserve the row selection of list view because it doesn't have SetSelected method like ListBox Control? Yep, set the ListView.HideSelection[^] property to false.

          - Nick Parker Microsoft MVP - Visual C#
          My Blog | My Articles

          T Offline
          T Offline
          takkung
          wrote on last edited by
          #4

          I 've already set ListView.HideSelect = false but it can't preserve the highlighting. I think because when I select an item and push move up/down button the items in ListView.Items has changed and ListView Control will be repaint so the highlighting will disappear. The problem is I want the highlighting is preserve at the selected item event through it has moved up or down. In ListBox control there 's SetSelected method to select an item to highlight but in ListView Control there is no such method. Thank you very much.

          N 1 Reply Last reply
          0
          • T takkung

            I 've already set ListView.HideSelect = false but it can't preserve the highlighting. I think because when I select an item and push move up/down button the items in ListView.Items has changed and ListView Control will be repaint so the highlighting will disappear. The problem is I want the highlighting is preserve at the selected item event through it has moved up or down. In ListBox control there 's SetSelected method to select an item to highlight but in ListView Control there is no such method. Thank you very much.

            N Offline
            N Offline
            Nick Parker
            wrote on last edited by
            #5

            Ok, I am with you now. I have actually run into this problem before. I solution is to perform the redrawing of the selected ListViewItem yourself.

            - Nick Parker Microsoft MVP - Visual C#
            My Blog | My Articles

            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