Solved

Update checked listbox items

Posted on 2009-05-11
3
661 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
Comment Utility
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
Comment Utility
That is what i was looking for.  Thanks.
0
 
LVL 48

Expert Comment

by:jpaulino
Comment Utility
Glad I could help!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now