Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. ListBox Control

ListBox Control

Scheduled Pinned Locked Moved Visual Basic
csharpdatabasedesignhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saam_cse
    wrote on last edited by
    #1

    I am working with access database and vb.net. I like to make two listBox in a form. first for product list and second for suppliers list of those corresponding products. When I click product list item corresponding suppliers of that product should be show in supplier list.Data retrive from products and suppliers table from database. I am a begainer of programming. Please help me to design the code.

    K J 2 Replies Last reply
    0
    • S Saam_cse

      I am working with access database and vb.net. I like to make two listBox in a form. first for product list and second for suppliers list of those corresponding products. When I click product list item corresponding suppliers of that product should be show in supplier list.Data retrive from products and suppliers table from database. I am a begainer of programming. Please help me to design the code.

      K Offline
      K Offline
      Khatri Mitesh
      wrote on last edited by
      #2

      Hiii I send a sample of code that use the Access Database (Test.mdb from C:) and that contain Table1 ( "Prodct" and "Supplier") fields.

      Dim myConnection As New OleDbConnection()
      dim oDataAdapter as dataAdapter
      Dim oDataTable as DataTable

      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      myconnection=new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Test.Mdb")
      oDataAdapter = New OleDbDataAdapter("Select * From Table1", myConnection)
      oDataTable=New DataTable
      oDataAdapter.Fill(oDataTable)
      ListBox1.DataSource = oDataTable
      ListBox1.ValueMember = "product"
      end sub

      Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
      dim sProduct as string=ListBox1.SelectedItem.ToString()
      if not isNothing (sproduct) then
      oDataAdapter = New OleDbDataAdapter("Select Supplier From Table1 where Product=" & sProduct & ", myConnection)
      oDataTable=New DataTable
      oDataAdapter.Fill(oDataTable)
      ListBox2.DataSource = oDataTable
      ListBox2.ValueMember = "Supplier"

      end if
      

      End Sub

      may be it helps you. Thanx ~Khatri Mitesh

      1 Reply Last reply
      0
      • S Saam_cse

        I am working with access database and vb.net. I like to make two listBox in a form. first for product list and second for suppliers list of those corresponding products. When I click product list item corresponding suppliers of that product should be show in supplier list.Data retrive from products and suppliers table from database. I am a begainer of programming. Please help me to design the code.

        J Offline
        J Offline
        John_Adams
        wrote on last edited by
        #3

        Hi, You need to implment the parent-child relationship between the two tables to get the desired results. You may try the following code snippet: --------------------------------------------------------------------------------------------------- BEGIN CODE Dim dc As OleDbConnection Dim connstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Nwind.mdb;" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim da As OleDbDataAdapter Dim dt As DataTable Dim dv As DataView dc = New OleDbConnection(connstr) da = New OleDbDataAdapter("Select * from Products", dc) dt = New DataTable da.Fill(dt) dv = New DataView(dt) Me.ListBox1.DataSource = dv End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Dim SupplierIDString = Me.C1Combo1.Columns("SupplierID").Text.ToString() Dim da As OleDbDataAdapter Dim dt As DataTable Dim dv As DataView dc = New OleDbConnection(connstr) da = New OleDbDataAdapter("Select * from Supplier where SupplierID = '" + SupplierID+ "'", dc) dt = New DataTable da.Fill(dt) dv = New DataView(dt) Me.ListBox2.DataSource = dv End Sub END CODE --------------------------------------------------------------------------------------------------- Hope this helps :).

        Regards, John Adams ComponentOne LLC

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups