If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Visual Basic > Multiple ComboBox Help!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-07-11, 01:40
vb_noob vb_noob is offline
Registered User
 
Join Date: Jan 2011
Posts: 1
Multiple ComboBox Help!

I have started a form application using visual studio 2010 express, vb programming. I'm using Access as my database.

My goal is to have ComboBox1 display a ProjectID and ComboBox2 display a TestNumber. Once the Test Number is selected I want my textboxes in the form to display fields from the row that the selected Test Number is in.

I have 2 tables set up right now "Projects" and "TestData". The "Projects" table has a [ProjectID] field, the remaining fields are just misc. project data. The "TestData" table also has the [ProjectID] field, and then the [TestNumber] field, then the remaining fields are misc. data.

Filling [ProjectID] in textbox1 is easy, in the properties I select DataSource from the Projects table, display [ProjectID] field. Where I'm having troubles is ComboBox2 displaying the TestNumber. If I select that field, it fills the ComboBox with EVERY TestNumber there is. So for Project 1 there is a test 1... over 500 projects, that combobox lists 500 Test 1's, no way to tell what project it belongs to...

How do I make ComboBox2 only display Test Numbers that pertain to the Project number selected in ComboBox1?

Using this code I can get it to work:

Dim ProjectNo, SQLString As String
Dim dtTableData As New DataTable()
Dim dbDataAdapter As OleDbDataAdapter
Dim ConnectionString As String = ("Provider = Microsoft.Jet.OLEDB.4.0;" & "Data Source = Database.MDB")
ProjectNo = ComboBox1.Text
SQLString = ("Select * FROM TestData WHERE ProjectID = " & "'" & ProjectNo & "'" & "")
dbDataAdapter = New OleDbDataAdapter(SQLString, ConnectionString)
dbDataAdapter.Fill(dtTableData)
ComboBox2.DataSource = dtTableData


I also imported system.data.oledb

Problem with this code is it will only filter data in ComboBox 2 but when you make your selection from ComboBox2 it won't activate the row so none of my textboxes fill. Before the code/query is ran it fills up the textboxes perfectly after every selection I just have no idea what project that report number belongs to. I can load the form with ComboBoxes and they display the corresponding row data because I use a "datasource" instead of textbox "databindings" but I don't want to use 20 comboboxes as my entry form...

Any help would be greatly appreciated as this has drove me nuts spending hours searching threads and youtube!
Reply With Quote
  #2 (permalink)  
Old 01-14-11, 06:51
corncrowe corncrowe is offline
Registered User
 
Join Date: Aug 2004
Location: Dallas, Texas
Posts: 347
Do you have a method to deal with cboTest changes? The selected cbo changed event should handle this with a call to the db and return the specific results. So you should have a sub to handle the request and populated the test boxes. Yes?
Reply With Quote
Reply

Tags
combobox, multiple combobox

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On