473,749 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

11 New Member
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 2226
Rabbit
12,516 Recognized Expert Moderator MVP
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
1315
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 third row to populate the textboxes below the grid that correspond to the various columns in the grid. The textboxes fill. I edit the data in one of the textboxes. As I lose focus I update the dataset and refresh the grid. Well the third row...
0
2085
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 arrow it is not working can u tell me what are the properties i have to add to slect an item in processcmdkey method.
1
6804
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 instructions on the item under the mouse but I can't get it to select with the right mouse. Anyone know how I can select an item with the right mouse button? Help would be greatly appreciated, Joe
2
5816
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 designation rs.Open "SELECT name,designation FROM profile", con cboMenu.Clear Do Until rs.EOF cboMenu.AddItem rs("name") cboMenu.ItemData(cboMenu.NewIndex) = rs("designation")
4
2420
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
10810
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 $5500
2
4567
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 automatically set the value of Textbox. For that I am using code in control source properties of Textbox Uptil here its fine. But after that, in some scenario,I have to change the value of that Textbox.
0
2469
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 it. I want to get the item's index which the mouse is pointing at. The problem is that I didn't find any event that been fired when mouse highlightd/hover to other item in the drop downlist of the Combobox.
1
2779
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 DataGridViews. Each has a BindingSource (and a BindingNavigator). The first view populates successfully based upon a Linq to SQL query in the Form Load (that is, the query is assigned to the DataSource of that view's BindingSource, and the BindingSource is...
2
1883
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 sender, EventArgs e) Object selectedRequirement = cmbMDCTestRequirements.selectedItem; Now this Object should be changed into an integer.
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9566
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9388
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.