i want to have 2 listbox. the first listbox is for the Main category and the other one is for the sub category. and by using sql 2005 for the database. help me plz. . .

for example my main category for the 1st listbox is
ADIDAS
CONVERSE
NIKE
SKETCHERS

and when i click one of the main categories it will
output the sub categories to the 2nd listbox.

I do not work with sql as database yet so I can't help with that, but here is the code to show you how to change the items in the second listbox depending on the user selection in the first listbox.

Public Class Form1
    Private adidas(4) As String
    Private converse(4) As String
    Private nike(4) As String
    Private sketchers(4) As String

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Store data form database here
        adidas(0) = "Absolado PS FG J"
        adidas(1) = "Absolado PS IN"
        adidas(2) = "Absolado PS IN DB"
        adidas(3) = "Absolado PS MG"
        adidas(4) = "Absolado PS TF"
    End Sub
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Select Case ListBox1.SelectedIndex
            Case 0
                'Clear the listbox of pervious data
                ListBox2.Items.Clear()
                'Adds the data in the array to the listbox
                ListBox2.Items.AddRange(adidas)
            Case 1
                ListBox2.Items.Clear()
                ListBox2.Items.AddRange(converse)
            Case 2
                ListBox2.Items.Clear()
                ListBox2.Items.AddRange(nike)
            Case 3
                ListBox2.Items.Clear()
                ListBox2.Items.AddRange(sketchers)
        End Select
    End Sub
End Class

Hopes this helps.

Same result as FreaKing , just a different style of coding.

Public Class Form1
    '// Category lists of string arrays.
    '// '-- should be easy to create if you can accesss the database.
    Private lstADIDAS() As String = {"ADIDAS - 1", "ADIDAS - 2", "ADIDAS - 3"}
    Private lstCONVERSE() As String = {"CONVERSE - 1", "CONVERSE - 2", "CONVERSE - 3"}
    Private lstNIKE() As String = {"NIKE - 1", "NIKE - 2", "NIKE - 3", "NIKE - 4", "NIKE - 5", "NIKE - 6", "NIKE - 7", "NIKE - 8", "NIKE - 9"}
    Private lstSKETCHERS() As String = {"SKETCHERS - 1", "SKETCHERS - 2", "SKETCHERS - 3"}

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        If Not ListBox1.SelectedIndex = -1 Then '// check if item is selected. -1 is a No Index.
            ListBox2.Items.Clear() '// clear ListBox2.
            Select Case ListBox1.SelectedItem '// add selections for Categories.
                Case "ADIDAS"
                    For Each myCoolShoe As String In lstADIDAS : ListBox2.Items.Add(myCoolShoe) : Next
                Case "CONVERSE"
                    For Each myCoolShoe As String In lstCONVERSE : ListBox2.Items.Add(myCoolShoe) : Next
                Case "NIKE"
                    For Each myCoolShoe As String In lstNIKE : ListBox2.Items.Add(myCoolShoe) : Next
                Case "SKETCHERS"
                    For Each myCoolShoe As String In lstSKETCHERS : ListBox2.Items.Add(myCoolShoe) : Next
            End Select
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With ListBox1.Items '// add items to ListBox1.
            .Add("ADIDAS") : .Add("CONVERSE") : .Add("NIKE") : .Add("SKETCHERS")
        End With
    End Sub
End Class

p.s., don't tell anyone, but it pays attention to view the entire thread before trying to provide a solution. :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.