473,473 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Use checkbox to select items in a listbox

Im very new to coding and I was wondering if anyone could please tell me how
to select all the items in a listbox when a checkbox is checked, and then
when the checkbox is unchecked to unselected the items in the listbox. Here
is the event I would like to put this into.

private void chkSelectAll_CheckedChanged(object sender,
System.EventArgs e)
{

}

Thank you for any help you can give me
Jul 21 '05 #1
1 1787
Hi Stephen,

private void chkSelectAll_CheckedChanged(object sender,
System.EventArgs e)
{
for(int i = 0; i < myListBox.Items.Count; i++)
{
myListBox.SetSelected(i, chkSelectAll.Checked);
}
}

Note that unless the ListBox' SelectionMode is set to one of the multi modes you will only see the last item selected.

--
Happy coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #2

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

Similar topics

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...
4
by: Thomas | last post by:
Hello; I am creating a multiselect listbox and I would like to use checkboxes to indicate which items are selected (rather than the default highlighting.) I would then place these selected items...
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...
2
by: Edmilson | last post by:
Hello All I have a Datalist where each "Item" contains a checkbox (among other things). I want the user to be able to click on one or more checkboxes, click the Send button, and have something...
2
by: gce | last post by:
What happens : When I first press the button, I get an listbox1 with a,b,c (correct: because of the addtoa(1, "a") addtoa(2, "b") addtoa(3, "c") When I check the checkbox, the eventhandler...
1
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we...
1
by: Stephen | last post by:
Im very new to coding and I was wondering if anyone could please tell me how to select all the items in a listbox when a checkbox is checked, and then when the checkbox is unchecked to unselected...
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...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.