473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to populate a second combobox when selecting item from the first combobox

Hi, Could anyone help me out!!!

I'm using VB 2010 and Access Database file. My problem is I'm unable to populate the second combobox when selection of item is made from the first combobox.

Here is my code:

Expand|Select|Wrap|Line Numbers
  1. Imports System.Data
  2. Imports System.Data.OleDb
  3.  
  4. Public Class Form1
  5.  
  6.     Dim con As New OleDbConnection
  7.     Dim dbProvider, dbSource As String
  8.     Dim ds1, ds2, ds3 As New DataSet
  9.     Dim da1, da2, da3 As OleDbDataAdapter
  10.     Dim sql1, sql2, sql3, selectcombo As String
  11.  
  12.  
  13.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  14.         dbProvider = "Provider=Microsoft.Jet.OLEDB.4.0;"
  15.         dbSource = "Data Source=C:\Users\Genius\Desktop\VBCode\Usertable.mdb"
  16.         con.ConnectionString = dbProvider & dbSource
  17.         con.Open()
  18.  
  19.         popcbo3()
  20.         popcbo2()
  21.  
  22.     End Sub
  23.  
  24.     Private Sub popcbo3()
  25.         sql3 = "SELECT DISTINCT username FROM Usertbl ORDER BY Username"
  26.         da3 = New OleDb.OleDbDataAdapter(sql3, con)
  27.         da3.Fill(ds3, "Username")
  28.         cboUser.DataSource = ds3.Tables(0)
  29.         cboUser.DisplayMember = "Username"
  30.         cboUser.ValueMember = "username"
  31.     End Sub
  32.     Private Sub popcbo2()
  33.         sql2 = "Select Distinct type From Usertbl where username= '" & cboUser.SelectedValue.ToString() & "'"
  34.         da2 = New OleDb.OleDbDataAdapter(sql2, con)
  35.         da2.Fill(ds2, "type")
  36.         cboType.DataSource = ds2.Tables(0)
  37.         cboType.DisplayMember = "type"
  38.         cboType.ValueMember = "type"
  39.     End Sub
  40. End Class
  41.  
>>> What code should be entered in the 'CboUser selected Item Index'??? If I put 'pop3 ()' no changes is made when I select from cboUser combobox in the contrary it duplicates the CboType combobox values...

Pls any suggestion from anyone... Thanks in advance
Jan 4 '13 #1
1 2220
Rabbit
12,516 Expert Mod 8TB
You should use one of the combo box events to call popcbo2, I don't know why you would call popcbo3 since popcbo2 is the one that has any sort of filtering in its SQL.
Jan 7 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Aaron Ackerman | last post by:
I have been having just on going problems with my MS Datagrids. I have NO idea what I am doing wrong. What is esentially happening is that say I have three records in my Dataset. I click on the...
0
by: koti | last post by:
hi i have written some code for selecting an item in combobox dropdown list which is in datagrid columm. by scrolling the mouse we select any item from the list. but by pressing the down key...
1
by: Joe Blow | last post by:
I would like to set the index in a ComboBox with the item under the mouse when I right click the mouse. I have set up a context menu with 2 items, all that works great. I want to execute the...
2
by: minu | last post by:
Hello all I am beginner to VB I populate all the professers name in one combobox ,If i select one professer name then thier designation will automatically display in textbox from database field ...
4
by: =?Utf-8?B?bWFydGluMQ==?= | last post by:
Hi, All, when starting run app, how to let user add item/edit item to comboBox on the Form, Thanks, Martin
4
by: billa856 | last post by:
Hi, I want to know how can we set the value of Textbox = value of field in table when we select a value form combobx. example i have a table customer CID CNAME CSALARY 1 Billa ...
2
by: billa856 | last post by:
Hi, I have one projrct in MS Access. I have one form in which there is one Combobx(PalletNo_combo) and one Textbox(ShippedQuantity). Now when I select an item from Combobox then it will...
0
by: alexia.bee | last post by:
Hi All, I am trying to get the index of an item that the mouse is pointing/ hovering at. Meaning, when user click the Combobox, droplist is show. When you hover the mouse on item, it highlight...
1
by: Arved Sandstrom | last post by:
This seems to be something so simple that none of the hundred-odd tutorials and forum threads that I have looked at (:-)) apparently thinks it's a problem. In a nutshell, I have two...
2
by: Frans vd Heuvel | last post by:
I have the following problem How do you select an item from a combobox when this combobox receives data from a SQL database. private void cmbMDCTestRequirements_SelectedValueChanged(object...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.