Most efficient way to select all items in a listbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got a "Select all" button under a listbox. What's the most efficient
way to select all the items in the listbox?
 
Dan said:
I've got a "Select all" button under a listbox. What's the most efficient
way to select all the items in the listbox?

\\\
With Me.ListBox1
.BeginUpdate()
For i As Integer = 0 To .Items.Count - 1
.SetSelected(i, True)
Next i
.EndUpdate()
End With
///
 
i still use the API for this.

Public Class Form1
Private Declare Auto Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal _
hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As
Integer) As Long
Const LB_SETSEL As Long = &H185&
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
For i As Integer = 0 To 40000
ListBox1.Items.Add(i)
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Call SendMessage(ListBox1.Handle, LB_SETSEL, True, -1)
End Sub
End Class


lance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top