?
Solved

Combo box values from array generated with table value using DataTable.Rows(index)("fieldname")

Posted on 2006-04-17
3
Medium Priority
?
277 Views
Last Modified: 2010-04-23
I cannot get my combo box to populate with an array that is based on a string in a table I use.

dt is the DataTable
index is a string that contains the index number from a DataRow
array_value is the field name that contains the text     {"", "Mr.", "Mrs.", "Dr."}

       Dim arrCriteria1() As String = dt.Rows(index)("array_value")
       cboCriteria1.DataSource = arrCriteria1

Regardless of what I do I continue to get a "specified cast is not valid" error.

I can however see that dt.Rows(index)("array_value") contains an appropriate value using MsgBox.
I also took the '{}' characters out of the array_value string and set up the command as follows:

       Dim arrCriteria1() As String = {dt.Rows(index)("array_value")}

It displayed the whole string..."", "Mr.", "Mrs.", "Dr."....as cboCriteria1.Text
I'm assuming it has to do with a conversion.  But I am without the knowledge of it.
This is a critical form in my design.  Without this capability I'm dead in the water.

Thanks for any help!

0
Comment
Question by:TSFLLC
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
PockyMaster earned 2000 total points
ID: 16470839
Check the Length of your string array. It probably says 1, because the value you are providing is just a string that looks like an array.

To make it into an array use Split like e.g.

    Dim a As String = """test"",""test2"",""test3""" ' example data like you are providing now

    Dim ar() As String = a.Split(","c) ' split the data on the comma

You might want to replace the " with nothing later, but I let that up to your imagination
0
 

Author Comment

by:TSFLLC
ID: 16470944
That worked like a charm!

My arrays in this form contain a limited number of values.

Therefore, I did remove the quotations altogether.  I also included in empty string for the first value so that no values would display in
my newly defined combo box.

Thanks much!
0
 
LVL 14

Expert Comment

by:PockyMaster
ID: 16470955
You're welcome!
0

Featured Post

Industry Leaders: 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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses

807 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