Solved

Update checked listbox items

Posted on 2009-05-11
3
662 Views
Last Modified: 2013-11-08
I have a checked list box on a windows form that I need to update the items that are checked.   The checkedlistbox is already populated with predefined items.    I need check the values in the list box that have been previously selected by the user.  The previously selected values have been stored in a comma seperated string.  As an example, the CheckListBox has the following items

Value1
Value2
Value3
Value4
Value5

When the user last updated the record, he selected Value1 & Value4.   Those values were stored in a database field as follows: "Value1, Value4".    I now need to first check to make sure Value1 and Value4 still exist in the checkbox list.  If they do exist I need to show them as being checked.  If they don't exist I need to add them to the list and then show them as being checked.

I am hoping that is possible but cant figure out how to do it.  
0
Comment
Question by:Mike_Stevens
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 24356181
Hi,
This is what I understood:

        ' Results from the db
        Dim dbResults As String = "Value3, Value4, Value5, Value6"
        Dim myArray() As String = dbResults.Split(","c)
 
        'Check for the items in the CheckedListBox and add it if doesn't found
        For Each item As String In myArray
            Dim x As Integer = Me.CheckedListBox1.FindStringExact(item.Trim)
            If x > 0 Then
                Me.CheckedListBox1.SetItemChecked(x, True)
            Else
                Me.CheckedListBox1.Items.Add(item.Trim, True)
            End If
        Next

Open in new window

0
 

Author Comment

by:Mike_Stevens
ID: 24356785
That is what i was looking for.  Thanks.
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24356803
Glad I could help!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question