• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

visual basic select item from dropdown

ganesh21

2[H]4U
Joined
Jan 22, 2006
Messages
2,373
Below is the issue:

Table1
Primary Key Description
1 Hardware
2 Software
3 Vending H
4 Vending S
5 Counting H
6 Counting S


Table2
1 Generic
2 Test

Table1 and Table2 are in sql

I would like if you select Hardware or Software, only Generic is visible from drop down and if you select Vending H to Counting S (3-6) only Test is visible.

Please note that this is for a drop down list.

What would be the best approach.
 
A more robust and flexible solution is to introduce another table that is used to associate items in Table1 with items in Table2. You then join across that table for your query when populating the second DDL.

i.e.,
Table 3
PK,Table1ID,Table2ID
1,1,1
2,2,1
3,3,2
4,4,2
5,5,2
6,6,2

If the items in table 1 will always and only ever be associated with a single item in table 2 you can also add another column to table 1 associating items in that table to the correct item in table 2
 
hi,

i thought about adding a third table. the problem is i can only have two tables.
 
Using what you said were table 1 and 2, I added a third column in table 1 to contain the id for table 2. (thus removing the need for a third table).

Table1:
lID (pk)
sDesc
lTable2ID

Table 2:
lID (pk)
sDesc


My form codE:
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.uxDataSet.Clear()
'-- just filling in your data as your described it.
        Me.uxDataSet.Table1.AddTable1Row(1, "Hardware", 1)
        Me.uxDataSet.Table1.AddTable1Row(2, "Software", 1)
        Me.uxDataSet.Table1.AddTable1Row(3, "V h", 2)
        Me.uxDataSet.Table1.AddTable1Row(4, "s h", 2)
        Me.uxDataSet.Table1.AddTable1Row(5, "c h", 2)
        Me.uxDataSet.Table1.AddTable1Row(6, "c s", 2)

        Me.uxDataSet.Table2.AddTable2Row(1, "Generic")
        Me.uxDataSet.Table2.AddTable2Row(2, "Test")

        ComboBox1_SelectedValueChanged(Nothing, Nothing)


    End Sub

    Private Sub ComboBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedValueChanged
        If Me.uxDataSet.Table2.Rows.Count = 0 Then Exit Sub

        Dim lChoice As Int32 = CInt(ComboBox1.SelectedValue)
        Dim lValue As Int32 = CType(Me.uxDataSet.Table1.FindBylID(lChoice), DataSet1.Table1Row).lTable2ID
        Dim tempDS As New DataSet1

        Dim bar() As Data.DataRow = Me.uxDataSet.Table2.Select("lID = " + lValue.ToString)
        tempDS.Table2.AddTable2Row(CInt(bar(0).Item("lID")), CStr(bar(0).Item("sDescription")))
        Me.ComboBox2.DataSource = tempDS

    End Sub
 
I did a simple select * from table...

Then i just populate and use bindingsource.

Thanks everyone for there help.
 
Back
Top