[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ListBox problem

Posted on 2004-10-31
8
Medium Priority
?
235 Views
Last Modified: 2012-05-05
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 ?
0
Comment
Question by:jokerxp888
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
8 Comments
 
LVL 14

Expert Comment

by:ptakja
ID: 12456515
What's the problem?
0
 

Author Comment

by:jokerxp888
ID: 12456532
i want to make it
listbox1 : display all categoryName
listbox2: display subCategoryName base on categoryName selected at the listbox1


0
 

Author Comment

by:jokerxp888
ID: 12457245
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 8

Expert Comment

by:wguerram
ID: 12465465
What's the error you get?
0
 
LVL 14

Accepted Solution

by:
ptakja earned 900 total points
ID: 12465607
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
 
LVL 8

Expert Comment

by:wguerram
ID: 12466049
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
 
LVL 14

Expert Comment

by:ptakja
ID: 12732659
I would say split between ptakja & wguerram.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question