Split Text In A Combobox Item To Multiple Items

  • Thread starter Thread starter Doctor GME
  • Start date Start date
D

Doctor GME

Guest
A drug index software

simply every combobox is filled from a field in the database like this:

519630276.jpg

but as marked with red arrow in field Routes when i choose dose 20

the opposite value B&B is listed in combobox named (Route) like this:

449057452.jpg

i want it to be split in separate items by the separator (&) to be viewed like this:

586877059.jpg

this is my code:

Dim cnn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Medication.accdb")

Dim da As OleDbDataAdapter

Dim cm As OleDbCommandBuilder

Dim cmd As OleDbCommand

Dim itemRoute As String()

Private Sub MedType1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles MedType1.SelectedIndexChanged

MedName1.Items.Clear()

MedDose1.Items.Clear()

MedRoute1.Items.Clear()

If MedType1.SelectedItem = ("Antibiotics") Then

Dim dt1 As New DataTable

dt1.Clear()

Dim sql As String = "SELECT * FROM Antibiotics"

da = New OleDbDataAdapter(sql, cnn)

cm = New OleDbCommandBuilder(da)

da.Fill(dt1)

For ii As Integer = 0 To dt1.Rows.Count - 1

MedName1.Items.Add(dt1(ii)(0))

Next

End If

End Sub

Private Sub MedName1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles MedName1.SelectedIndexChanged

MedDose1.Items.Clear()

MedRoute1.Items.Clear()

If MedType1.SelectedItem = ("Antibiotics") Then

Dim dt2 As New DataTable

dt2.Clear()

Dim sql2 As String = "SELECT * FROM Antibiotics WHERE Antibiotics = '" & MedName1.SelectedItem & "'"

da = New OleDbDataAdapter(sql2, cnn)

cm = New OleDbCommandBuilder(da)

da.Fill(dt2)

Dim doses As String = dt2(0)(1)

Dim dose As String() = doses.Split("-")

For ii As Integer = 0 To dose.Count - 1

MedDose1.Items.Add(dose(ii))

Next

Dim routes As String = dt2(0)(2)

Dim route As String() = routes.Split("-")

itemRoute = route

End If

End Sub

Continue reading...
 
Back
Top