Solved

Update checked listbox items

Posted on 2009-05-11
3
664 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

740 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