|
-
Jan 11th, 2011, 06:31 PM
#1
Thread Starter
Junior Member
[RESOLVED] How to add items to a checked listbox
I was wondering if there was any tut on how to aan item to a checked listbox thats already populated?
I thought of making a button and a text box .and when u push the button it add whats ever in the text box to the checklist box . but cant find any tut or example any help is appreciated.
-
Jan 11th, 2011, 07:06 PM
#2
Re: How to add items to a checked listbox
The CheckedListBox has an Items property. That collection has an Add method. That's it. You don't need a tutorial. You just need to read the documentation.
http://msdn.microsoft.com/en-us/libr...edlistbox.aspx
That Help topic has a code example that shows the aforementioned method being called. Moreover, it even shows an item being added form a TextBox on the Click of a Button, i.e. exactly what you're suggesting. ALWAYS read the documentation first.
-
Jan 11th, 2011, 07:55 PM
#3
Thread Starter
Junior Member
Re: How to add items to a checked listbox
sorry id dont think i worded it right i want to the end user to be able to add things to the check box list .i know how to add them myself...but it just somemethod for the end user of my db to add stuff to the check box without me having to update the program...
hope that explains what im loking for..
-
Jan 11th, 2011, 08:04 PM
#4
Lively Member
Re: How to add items to a checked listbox
Add a TextBox and a Button
Under the button's code, add this:
Code:
CheckedListBox1.Items.Add(TextBox1.Text)
Basic. if you get errors work it out... and if you can't figure it out sendz me a pm.
-
Jan 11th, 2011, 08:19 PM
#5
Re: How to add items to a checked listbox
There is only one way to add items to a CheckedListBox and that's in code. Even when you add items in the designer, that simply generates the code to add them for you. So, if you want the user to be able to add items then you do it as already explained.
If you want to save data between sessions then that is a different thing altogether, and doesn't really relate to the CheckedListBox specifically. The principle would be the same no matter what the data was and how it was being displayed. Basically, you need to persist the data somewhere before closing and then load it again at startup. That somewhere could be a database, a text file, an XML file, applications settings or various other options.
My first suggestion would be to use application settings. To do that, you can open the Settings page of the project properties and add a StringCollection. You would then add your default items to that. At startup, load the items from that StringCollection into your control. Add new items to the control during the session and, before you shut down, refresh the StringCollection with the contents of the control.
One issue there is that the checked state of the items won't be saved. To handle that you could combine the text and checked state of an item into a single string to store in the setting. You can then parse the data on load to get the two separate values.
Using My.Settings will also use a separate list for each Windows user. That might not matter if only one person uses the machine. It also might be exactly what you want, or it might not be acceptable. In that final case, you'd have to use some other method to persist the data.
-
Jan 11th, 2011, 08:54 PM
#6
Thread Starter
Junior Member
Re: How to add items to a checked listbox
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|