Solved

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

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

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!

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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