?
Solved

CheckedListbox.SelectedItem.ToText Doesn't Work

Posted on 2005-03-28
8
Medium Priority
?
396 Views
Last Modified: 2008-01-09
I have a CheckedListBox in VB.NET.  I am trying to load the checked items into a string with the following code:

            Dim sLocal As String
            Dim iLocal, iLocalCounter As Integer
            With clstCircuits
                iLocal = .SelectedItems.Count
                For iLocalCounter = 0 To iLocal
                    If sLocal <> "" Then
                        sLocal = sLocal & "' "
                    End If
                    sLocal = sLocal & .SelectedItem.ToString
                Next iLocalCounter
            End With

Instead of getting the selected item, I get:
"System.Data.DataRowView"

Also, intellisense does not offer "ToText" as a method when I am typing, only "GetType"

I'm probably missing something easy!

Thanks,
Gerry
0
Comment
Question by:gerrystrat
[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
  • 4
  • 3
8 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13646933
What is the DataSource and DataMember properties set to?

Bob
0
 
LVL 42

Expert Comment

by:frodoman
ID: 13646940
Depending on what you have in the listbox you may need to just use .SelectedItem

If you have a custom object then you'll need to use whatever method your object exposes to get a text description.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13646952
You need to set both properties to get the databinding correct.

Bob
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:gerrystrat
ID: 13647061
I set .DataSource and .DataMember in the form load event:

            Dim strSQL As String
            strSQL = "SELECT DISTINCT strCircuit FROM tblCHImportData"
            strConn = "Provider=SQLOLEDB;Data Source=SERVER;" & _
            "Initial Catalog=WSurvey;Trusted_Connection=Yes;"
            Dim daCircuits As New OleDbDataAdapter(strSQL, strConn)
            Dim dsCircuits As New DataSet
            daCircuits.Fill(dsCircuits, "tblCHImportData")
            clstCircuits.DataSource = dsCircuits.Tables("tblCHImportData")
            clstCircuits.DisplayMember = "strCircuit"

The data is showing up in the CheckedListBox just fine...
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1000 total points
ID: 13647102
Oh, I get it, you are going to have to cast each SelectedItem to a DataRow to get the value of the text:

Dim builderList As New System.Text.StringBuilder

For Each item As Object In clstCircuits.SelectedItems

   If TypeOf item Is DataRowView Then
      builderList.Append("'" & DirectCast(item, DataRowView)("strCircuit")
   End If

Next item

sLocal = builderList.ToString

Bob
0
 

Author Comment

by:gerrystrat
ID: 13647231
Thanks, that works!  I ended up using "CheckedItems" instead os "SelectedItems" and it also works.  I am moving from VB6 to VB.NET.  I would have never thought of System.Text.StringBuilder!  I need to learn more about casting.

Gerry
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13647246
Welcome to the wonderful world of .NET.  There are plenty of experts here to answer the myriad of questions that I am sure you will be asking in the future.

Bob
0
 

Author Comment

by:gerrystrat
ID: 13647276
Great, thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 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