how to select all item in listview?
For i = 0 To lvList.Items.Count - 1
lvList.Items(i).Selected = True
Next i
PrintToolStripMenuItem.PerformClick()
how to select all item in listview?
For i = 0 To lvList.Items.Count - 1
lvList.Items(i).Selected = True
Next i
PrintToolStripMenuItem.PerformClick()
Both and demonstrate the straightforward approach of iterating the items and marking them selected. That works, but a few practical points and alternatives are often missed and can save time when selection appears not to behave as expected.
MultiSelect = True (otherwise only one item can be selected). See the official MultiSelect docs: ListView.MultiSelect.BeginUpdate() before and EndUpdate() after making changes. Details: ListView.BeginUpdate.HideSelection = False or call Focus() / EnsureVisible(...) on an item you want shown.CheckBoxes and the item Checked state so the marks remain independent of focus or selection behavior: ListViewItem.Checked.Also note that programmatic selection will raise selection events. If those handlers should not run during a bulk change, use a simple guard flag to ignore events while the operation is in progress. Finally, rather than simulating a menu click with PerformClick(), call the printing or processing routine directly after making the selection so timing and UI state are explicit.
One way is
For Each item As ListViewItem In ListView1.Items
item.Selected = True
Next
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.