Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-09-23
1
Medium Priority
?
930 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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

773 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