Solved

How to retrieve checked values from databound checkedlistbox windows vb.net

Posted on 2004-09-23
1
919 Views
Last Modified: 2012-08-13
I have a Checkedistbox bound to a dataset. I need to get out the checked selecteditemvalue from each one that is checked to get send to my insert query for another table. this is multi select. I need code for selectedindexchages of a button onclick either one will do. thank you.

here is my code on popluating the checklistbox1

 Dim myconn As OleDbConnection = New OleDbConnection(Cnn)
        Dim mydap As New OleDbDataAdapter
        Dim dbcom As OleDbCommand
        Dim mydsLmat As New DataSet

        Dim strSQL As String
        strSQL = "SELECT PickID, PickName FROM Picklist WHERE Picktype = 'O' OR Picktype = 'C'"

        Try
            CheckedListBox1.DataSource = Nothing
            dbcom = New OleDbCommand(strSQL, myconn)
            mydap = New OleDbDataAdapter(dbcom)
            myconn.Open()
            CheckedListBox1.Items.Clear()
            mydsLmat = New DataSet

            mydap.Fill(mydsLmat, "Picklist")
            CheckedListBox1.DisplayMember = ("PickName").ToString
            CheckedListBox1.ValueMember = ("PickID").ToString
            CheckedListBox1.DataSource = mydsLmat.Tables(0)
            myconn.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
            mydsLmat.Dispose()

        End Try
0
Comment
Question by:astafate
1 Comment
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 500 total points
ID: 12140056
Here what I am doing:

        Dim IDString As String
        If CheckedListBox1.CheckedIndices.Count > 0 Then
            Dim i As Int32
            For Each i In CheckedListBox1.CheckedIndices
                CheckedListBox1.SelectedIndex = i
                IDString &= CheckedListBox1.SelectedValue & ","
            Next
            IDString = IDString.Substring(0, IDString.LastIndexOf(","))
            MsgBox(IDString)
        Else
            MsgBox("Please check the items you want.")
        End If

-Baan
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

861 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

23 Experts available now in Live!

Get 1:1 Help Now