Link to home
Start Free TrialLog in
Avatar of Anthony Matovu
Anthony MatovuFlag for Uganda

asked on

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"
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial