Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Update checked listbox items

Posted on 2009-05-11
3
Medium Priority
?
673 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
jpaulino earned 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

705 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