Click here to Skip to main content
15,173,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a form with CheckedListBox, that have a DisplayMember and ValueMember, and a button, when it is Clicked the Checked values should appear in a textbox showing the "DisplayMember | ValueMember" for each Checked Item
Posted
Updated 29-Oct-21 10:46am

found the solution :)
<pre lang="vb">
For Each item As DataRowView In lst.CheckedItems
txtb.Text += (item(lst.ValueMember).ToString() + " | " item(lst.DisplayMember).ToString())
txtb += " "
Next
</pre>
   
found the solution Smile | :)
<pre lang="vb">
For Each item As DataRowView In lst.CheckedItems
txtb.Text += (item(lst.ValueMember).ToString() + " | " item(lst.DisplayMember).ToString())
txtb += " "
Next
</pre>
   
''' <summary>
  ''' Return a list of Checked items from a checkedlistbox
  ''' if ValueMember=true the Checkedlistbox must the ValueMember property set to a field name and the valuemember will be returned.
  ''' if ValueMember=false will return the index of item in the CheckedListBox
  '''     ''' </summary>
  ''' <param name="CLB">The Checklistbox</param>
  ''' <param name="Valuemember">True/False</param>
  ''' <returns></returns>
  Public Function GetCheckListBoxValues(ByRef CLB As CheckedListBox, Optional ByVal Valuemember As Boolean = False) As String()
      GetCheckListBoxValues = Nothing
      Try
          If CLB.CheckedItems.Count > 0 Then 'Check to see if any objects in the list are checked.
              Dim Int1 As Integer = 0 'Generic Counter
              Dim Rtn(CLB.CheckedItems.Count - 1) As String 'Define a return variable
              Dim fn As String = CLB.ValueMember 'if the Valuemember is being used the find the field name of the the Valuemember
              For Each item As Data.DataRowView In CLB.CheckedItems 'Loop through each checked item
                  If IsNothing(item) Then Continue For
                  If Valuemember Then
                      Rtn(Int1) &= item.Item(fn).ToString 'Return the ValueMember
                  Else
                      Rtn(Int1) &= CLB.CheckedItems.IndexOf(item).ToString  'Return the index of the item
                  End If
                  Int1 += 1
              Next
              GetCheckListBoxValues = Rtn
          End If
      Catch ex As Exception
          ex.Source = System.Reflection.MethodBase.GetCurrentMethod.Module.Name & "." & System.Reflection.MethodBase.GetCurrentMethod().Name
          ErrLogging(ex)
      End Try
  End Function
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900