Click here to Skip to main content
15,888,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

I'm trying to figure out, why after clicking once again on my combobox, next combobox remember items from previous selection.

I have 7 comboboxes (items for cb's are storen in SQL table). For each I have Sub to fill it with the items, like this:

VB
Sub fillAdditional()
    Dim var As String = Convert.ToString(cbAccount.SelectedItem)
    Dim var2 As String = Convert.ToString(cbTower.SelectedItem)
    Dim var3 As String = Convert.ToString(cbProcess.SelectedItem)
    strsql = "Select Distinct Additional from tblAdministratorData where AccIc in ( Select AID from tblAccount)"
    '((TimerAccount like '%" + var + "%') AND (TimerTower like '%" + var2 + "%') and (TimerProcess like '%" + var3 + "%'))"
    Dim acscmd As New SqlCommand
    acscmd.CommandText = strsql
    acscmd.Connection = cn
    acsdr = acscmd.ExecuteReader
    While (acsdr.Read())
        Me.cbAdditional.Items.Add(acsdr("Additional"))
    End While
    acscmd.Dispose()
    acsdr.Close()
End Sub


I'm calling each after Combobox_SelectedIndexChange like:

Me.fillAdditional()


I was trying to do it, by adding

cbTower.SelectedIndex = cbTower.FindString(cbAccount.SelectedText)


to Combobox_SelectedIndexChange, but no value added...

Could someone tell me, what I'm doing wrong?
Thank you in advance!
Best Regards
Posted
Updated 5-Jul-13 4:06am
v2

1 solution

Dim var As String = cbAccount.SelectedItem
strsql = "Select Distinct TimerTower from tblAccount  where (TimerAccount = '" + var + "')"
Dim acscmd As New SqlCommand
acscmd.CommandText = strsql
acscmd.Connection = cn
acsdr = acscmd.ExecuteReader
'If cbTower.SelectedItem = "" Then
While (acsdr.Read())
    Me.cbTower.Items.Add(acsdr("TimerTower"))
End While
acscmd.Dispose()
acsdr.Close()
 <pre></pre>

It was because of Select statement was wrong.

Best regards!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900