Solved

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

Posted on 2004-09-23
1
918 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

22 Experts available now in Live!

Get 1:1 Help Now