473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Most efficient way to select all items in a listbox

Dan
I've got a "Select all" button under a listbox. What's the most efficient
way to select all the items in the listbox?
Dec 6 '05 #1
2 1421
"Dan" <Da*@discussions.microsoft.com> schrieb:
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 6 '05 #2
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

"Dan" <Da*@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.com...
I've got a "Select all" button under a listbox. What's the most efficient
way to select all the items in the listbox?

Dec 6 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: DCount17 | last post by:
I have used the following code, but I get an error. I'm using C#. When the checkbox is selected, I want to select all items in lstTeams (90 items) so the user doesn't have to manually select each...
4
by: headware | last post by:
I have a <select> control that contains many entries. It allows the user to multi-select a group of them, click a button, and store the selected data in a database. Normally they do this starting...
9
by: Susan Bricker | last post by:
Hi. I have two questions ... (1) I want to use a Listbox to enable the user to select 1 or many items from the list. However, I'm having trouble figuring out how to find out t which items have...
3
by: ted | last post by:
Hi, I can't figure out how to set multiple items in a ListBox to selected when the listbox is in a User Control. When the ListBox is set in directly into a form I can use the following:...
1
by: sab | last post by:
Hi, We have a web form with a listbox. The listbox is a multiple select listbox and has data that looks something like: ALL Unit 1 Unit 2 Unit 3 Note: "ALL" is always the first item in...
2
by: Alex Simic | last post by:
Dear all I am very desperate with my problem and you might be probably my last chances for this issue. I have a listbox which is binded to a DataTable. I would like in the program to select...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
4
by: Vincent | last post by:
I have a list box that is bound to a table with many records. I have a select all button that when clicked, obviously, selects all of the items in the list box. However, it takes a fairly long...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.