ListBox problem

i have 2 table
table1 : categoryID,CategoryName,Desc
table2: subCategoryID,SubCateogryName,subCategoryDesc,CategoryID
link by CategoryID

i have 2 listbox
listbox1 : display all categoryName
listbox2: display subCategoryName base on categoryName selected at the listbox1

my code :

Private ds As DataSet = New DataSet

Public Sub getCategory(ByVal ds As DataSet)
        Dim strSql As String = "select * from Category"
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(strSql, DBConn)
        da.Fill(ds, "Category")

    End Sub
    Public Sub getSubCategory(ByVal ds As DataSet)
        Dim strSql As String = "select * from SubCategory"
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(strSql, DBConn)
        da.Fill(ds, "SubCategory")
    End Sub

       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        getCategory(ds)
        getSubCategory(ds)
        ListBox1.DataSource = ds.Tables("category")
            ListBox1.DisplayMember = ds.Tables("category").Columns(1).ToString
            ListBox1.ValueMember = ds.Tables("category").Columns(0).ToString
    End Sub


any can help me ?
jokerxp888Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ptakjaCommented:
What's the problem?
0
jokerxp888Author Commented:
i want to make it
listbox1 : display all categoryName
listbox2: display subCategoryName base on categoryName selected at the listbox1


0
jokerxp888Author Commented:
i have error at

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            ListBox2.DataSource = ds.Tables("subCategory").Select("cat_id=1")
            ListBox2.DisplayMember = ds.Tables("subCategory").Columns(1).ToString
            ListBox2.ValueMember = ds.Tables("subCategory").Columns(0).ToString
        Catch err As Exception
            MsgBox(err.ToString)
        End Try
    End Sub
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

wguerramCommented:
What's the error you get?
0
ptakjaCommented:
The problem is on the line:

ListBox2.DataSource = ds.Tables("subCategory").Select("cat_id=1")

The Select method of the Tables object returns an Array of DataRow objects. So you have a couple options:

1) Take the array of DataRow objects and loop through them adding them to the Listbox sort of manually.
2) Add the array of DataRow objects to another DataTable and then bind the listbox to the new data table.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
wguerramCommented:
ptakja took a good point.

You can use the default view of the datatable

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            dim dv as Data.DataView = ds.Tables("subCategory").DefaultView

            dv.Sort = "cat_id"
            dv.RowFilter = "1"

            ListBox2.DataSource = dv
            ListBox2.DisplayMember = ds.Tables("subCategory").Columns(1).ToString
            ListBox2.ValueMember = ds.Tables("subCategory").Columns(0).ToString
        Catch err As Exception
            MsgBox(err.ToString)
        End Try
    End Sub
0
ptakjaCommented:
I would say split between ptakja & wguerram.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.