3 Replies - 484 Views - Last Post: 28 December 2017 - 09:15 AM Rate Topic: -----

#1 wilrodiz   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-December 08

Listview in Visual Basic

Posted 27 December 2017 - 06:07 PM

How to select all items of a listview at runtime>
Is This A Good Question/Topic? 0
  • +

Replies To: Listview in Visual Basic

#2 Radius Nightly   User is offline

  • D.I.C Regular

Reputation: 33
  • View blog
  • Posts: 291
  • Joined: 07-May 15

Re: Listview in Visual Basic

Posted 28 December 2017 - 12:06 AM

I guess if you know how to select specific line by number, such as select 5 to select 5th, -1 or 0 should be to select them all, like SetSelected (-1). I dont think making a loop to select one by one would work, because when you set new selection, previous one/all are gonna be removed.

Check this: http://www.dreaminco...ms-in-listview/

This post has been edited by Radius Nightly: 28 December 2017 - 12:13 AM

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw   User is offline

  • Bouncy!
  • member icon

Reputation: 6563
  • View blog
  • Posts: 26,615
  • Joined: 12-December 12

Re: Listview in Visual Basic

Posted 28 December 2017 - 12:22 AM

For which type of application? WinForms?

@Radius The information you have provided is for a ListBox, not a ListView, but is also incorrect. 5 Would select the 6th item, 0 would be the first. -1 would, for some methods, cause deselection (not select all) but, for SetSelected, would raise an exception (according to the docs).
Was This Post Helpful? 0
  • +
  • -

#4 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1505
  • View blog
  • Posts: 3,809
  • Joined: 01-February 13

Re: Listview in Visual Basic

Posted 28 December 2017 - 09:15 AM

Make sure you have the MultiSelect property of the ListView set to True so that more than one item can be selected at a time. Then simply use a For Each loop to iterate through all the ListViewItems in the ListView and set each one's Selected Property to True.
        ListView1.MultiSelect = True

        For Each lvi As ListViewItem In ListView1.Items
            lvi.Selected = True
        Next


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1