reading a value from a database to a combobox

I want to read data from a datafile and display on the form. I have problems with the comboboxes. I want to select a combobox value and its displays the corresponding text.

I am using the code below,
ctl is a group box, i check if the control is in that group box,

drd = cmd.ExecuteReader
        If drd.HasRows Then
            Do While drd.Read
                For t As Int16 = 3 To 5
                    ctl = Me.Controls("TabControl1").Controls("tab" & t - 2.ToString & "nc").Controls("GroupBox" & t.ToString)
                    If ctl.Controls.ContainsKey("T" & drd("vcode") & "") Then
                        CType(ctl.Controls("T" & drd("vcode")), ComboBox).SelectedValue = 1
                        CType(ctl.Controls("C" & drd("vcode") & ""), TextBox).Text = drd("addnotes") & ""
                        CType(ctl.Controls("C" & drd("vcode") & ""), TextBox).ForeColor = Color.Black
                    End If
                Next
            Loop
        End If


This is how i populated the combox,


arryn = New ArrayList
        arryn.Add(New cValue(" ", 0))
        arryn.Add(New cValue("Yes", 1))
        arryn.Add(New cValue("No", 2))

         CType(ctl.Controls("TN" & Format(i, "00").ToString), ComboBox).DataSource = arryn
         CType(ctl.Controls("TN" & Format(i, "00").ToString), ComboBox).DisplayMember = "Display"
         CType(ctl.Controls("TN" & Format(i, "00").ToString), ComboBox).ValueMember = "Value"
LVL 1
Anthony MatovuBusiness Analyst, MTN UgandaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeCruiserCommented:
I think you problem is that you are using an array as datasource so your DisplayMember and ValueMember are not really working. Try replacing

arryn = New ArrayList
        arryn.Add(New cValue(" ", 0))
        arryn.Add(New cValue("Yes", 1))
        arryn.Add(New cValue("No", 2))

         CType(ctl.Controls("TN" & Format(i, "00").ToString), ComboBox).DataSource = arryn
         CType(ctl.Controls("TN" & Format(i, "00").ToString), ComboBox).DisplayMember = "Display"
         CType(ctl.Controls("TN" & Format(i, "00").ToString), ComboBox).ValueMember = "Value"



with this


Dim dTable As New DataTable
dTable.Columns.Add("Display", GetType(String))
dTable.Columns.Add("Value", GetType(Integer))
Dim dRow as DataRow = dTable.NewRow()
dRow(0) = ""
dRow(1) = 0
dTable.Rows.Add(dRow)
Dim dRow2 as DataRow = dTable.NewRow()
dRow2(0) = "Yes"
dRow2(1) = 1
dTable.Rows.Add(dRow2)
Dim dRow3 as DataRow = dTable.NewRow()
dRow3(0) = "No"
dRow3(1) = 2
dTable.Rows.Add(dRow3)

         CType(ctl.Controls("TN" & Format(i, "00").ToString), ComboBox).DataSource = dTable
         CType(ctl.Controls("TN" & Format(i, "00").ToString), ComboBox).DisplayMember = "Display"
         CType(ctl.Controls("TN" & Format(i, "00").ToString), ComboBox).ValueMember = "Value"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.