Solved

Checked listbox, how to find checked items?

Posted on 2007-11-21
11
1,941 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
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 6

Expert Comment

by:carmodyk
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 6

Expert Comment

by:carmodyk
Comment Utility
You have to reference each string array item individually.

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

D
0
 
LVL 3

Author Comment

by:leeds2000
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry PaulHews, you must have posted as I was witting the code...  but hey nice answer!
0
 
LVL 3

Author Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

728 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

13 Experts available now in Live!

Get 1:1 Help Now