Solved

Checked listbox, how to find checked items?

Posted on 2007-11-21
11
1,949 Views
Last Modified: 2012-06-21
Ive been struggling with finding the checked items inside a checklistbox

So far i only figured out how to use a selected (the blue select) instead of the checkboxes to drag out information from these, how do i use the check function? :)

Below is the code for selected type
Dim valgetkunde As String = Me.checkedlistbox.SelectedItem

Open in new window

0
Comment
Question by:leeds2000
[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
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 20330901
You can access the checked items using the CheckedItems collection.  :)
For Each CheckItem As String In Me.CheckedListBox1.CheckedItems
    Debug.WriteLine(CheckItem)
Next

Open in new window

0
 
LVL 3

Author Comment

by:leeds2000
ID: 20330928
I need the checked items to be inside a variable, like the code i wrote above, this is becouse i need the information from the checked items in a split() array
0
 
LVL 3

Author Comment

by:leeds2000
ID: 20330962
This is the code i need adapted to the checked item

        Dim valgetkunde As String = Me.chdlistkunde.SelectedItem
        Dim valgetvare As String = Me.chkdlistvare.SelectedItem
        
        Dim kundetabell() As String = valgetkunde.Split()
        Dim varetabell() As String = valgetvare.Split()
 
        Dim kundenr As Integer = kundetabell(0)
        Dim varenr As Integer = varetabell(0)

Open in new window

0
Technology Partners: 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!

 
LVL 6

Expert Comment

by:carmodyk
ID: 20331073
Dim strArray(CheckedListBox1.CheckedIndices.Count()) As String

        For intCount As Integer = 0 To CheckedListBox1.CheckedIndices.Count - 1
            If CheckedListBox1.GetItemCheckState(intCount) = CheckState.Checked Then
                strArray(intCount) = CheckedListBox1.Items(intCount).ToString

            End If
0
 
LVL 3

Author Comment

by:leeds2000
ID: 20331127
when i try to put the strArray in a msgbox to test the values, like this:

msgbox(strArray) i get a error saying cant convert to string

0
 
LVL 6

Expert Comment

by:carmodyk
ID: 20331189
You have to reference each string array item individually.

msgbox(strArray(0)), msgbox(strArray(1)), etc...

D
0
 
LVL 3

Author Comment

by:leeds2000
ID: 20331281
I still dont understand how this will make a variable with the data from the checklistbox

I need the checked item data (or values)

I have customers in the checkedlistbox, when i check "Jimbo Jupiter" in my checked listbox i need a variable that contains this string
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 250 total points
ID: 20331572
Your checkedlistbox can hold more than one checked item.  Thus it is exposed as a collection.  Since you wish to load all items from chdlistkunde into an array named kundetabell, you can do that without splitting from a string.
Dim kundetabell(chdlistkunde.CheckedItems.Count - 1) As String
chdlistkunde.CheckedItems.CopyTo(kundetabell, 0)

Open in new window

0
 
LVL 2

Expert Comment

by:SZachmann
ID: 20331587
If your checkbox has type different than string then you will need to declare the array as a differant type.
Dim strArray(CheckedListBox1.CheckedItems.Count - 1) As String
CheckedListBox1.CheckedItems.CopyTo(strArray, 0)

Open in new window

0
 
LVL 2

Expert Comment

by:SZachmann
ID: 20331598
Sorry PaulHews, you must have posted as I was witting the code...  but hey nice answer!
0
 
LVL 3

Author Comment

by:leeds2000
ID: 20331670
Yes worked nicely, little harder to do this then the selected item, but atleast its working, thanks for the help :D
0

Featured Post

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

627 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