473,387 Members | 1,529 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,387 software developers and data experts.

get selected combobox item to display its values to listbox

25
hello, I need some some help regarding my project. I have a form with a combobox, and listbox. The combobox is populated with illnesses stored in the database. Now, when user select an illness in the combobox, the symptoms should be listed in the listbox. Here's how my table looks like:
f_id | illness | symptoms
1 | fever | dizziness
2 | fever | cold
3 | fever | hot temperature
4 | asthma | dizziness
5 | asthma | difficulty in breathing
6 | asthma | pale
so if user select fever from combobox, listbox will have dizziness, cold, hot temperature. I've already tried something but its not working:
Expand|Select|Wrap|Line Numbers
  1. Dim dtr As MySqlDataReader
  2.         Dim cmd As New MySqlCommand
  3.         With Me
  4.             Call Connect()
  5.             cmd.Connection = myConn
  6.             cmd.CommandText = STRSQL
  7.  
  8.             STRSQL = "select sym from symptoms where ill = @rec"
  9.             cmd.Parameters.AddWithValue("rec", cmbRecord.Text)
  10.  
  11.             dtr = cmd.ExecuteReader
  12.             Dim symp As New List(Of String)
  13.             While dtr.Read()
  14.                 symp.Add(dtr("symptoms"))
  15.             End While
  16.             lstSymp.DataSource = symp
  17.             dtr = Nothing
  18.             cmd = Nothing
  19.             myConn.Close()
  20.             Call Disconnect()
  21.         End With
  22.  
Please help me correct the code. Thanks in advance.
Feb 24 '13 #1
3 2543
zmbd
5,501 Expert Mod 4TB
The main bit of advise I have for you:

Your database doesn't sound/appear to be normalized from the data you've posted; thus your queries for the list box are going to be so much harder to code.


Now, because I've not done anything with the dot-net stuff the best I can offer you is some information on the database design and hopefully some VBA that you can modify or at least use as inspiration for your VB code:

The database theory will apply to all RDMS just the implementation will vary at tad from one to the next:
A Tutorial for Access
Database Normalization and Table Structures.
Once you get your database normalized, you'll see how much easier it will be to write the SQL and set it as the record source for your list box.
See right now, "Fever" for example has three id's associated with it... if you had a normalized database you'd only have one.


I think the cascade will be more what you're looking at modifying for use in your listbox - you should be able to adapt these to VB.Net fairly easily I would hope.
Form Filter and Cascade
From the Bytes > Sitemap > Microsoft Access / VBA Insights
42.Cascaded Form Filtering
156.Cascading Combo/List Boxes
168.Example Filtering on a Form.
Feb 24 '13 #2
kumsay
25
Thanks for the advise sir, i'll take a look at it. Anyway my problem is solved now, I reviewed all my code on the class and realized I placed the code I gave above in the wrong event. I placed it on the lstSymp_SelectedIndexChanged event instead of putting it on the cmbRecord_SelectedIndexChanged event. The code above is working properly. Sorry for bothering ^_^v
Feb 24 '13 #3
zmbd
5,501 Expert Mod 4TB
Sorry for bothering ^_^v
Absolutely no need to apologize!
In fact, your original post and follow-up may help someone else with the same or similar question.
I'm glad that the solution turned out to be an "easy" one... those are the best kind! :)
Feb 24 '13 #4

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

Similar topics

5
by: hiroshi ochi | last post by:
Hello, Using MSIE 6.0 and above, with javascript is it possible to display an individual tooltip for each item in a listbox? I need this functionality to show the listitems that are longer...
2
by: Peder Y | last post by:
Anyone knows if there is some kind of property or function that will return the last selected/deselected item/index in a multiselect ListBox? SelectedIndex will point to first index in the...
2
by: VMI | last post by:
Is it possible to display something in a combobox and store something else? For example, can I display "Query for active employees" and save the actual query in the same combobox item? That way...
2
by: Alpha | last post by:
How do I change the selected item in a listbox according to a Combox's selected item on the same form? The Combox is from a different table in the same dataset as the Listbox uses. Combox's...
0
by: Craig Buchanan | last post by:
I'm having a hell of a time trying to determine which item is selected in a single-select listbox when the listbox autoposts. for some reason, the ..SelectedIndex is always -1 and the...
3
by: amber | last post by:
Hello again : How do I specify which item in a listbox I want selected The listbox is already populated, and if the user types in a value into a textbox, I want that value to be highlighted in...
3
by: Sam | last post by:
Hi, How can I add an item to a listbox so that when we select an item afterward, we'll get the id associate, like the display member and the value member for a combobox ? regards
3
by: Michael Meckelein | last post by:
Hello, I run into trouble move down a selected item in a listbox. The code moving down the item is the following one: for (int j = lv.SelectedItems.Count-1; j >=0; j--) { ListViewItem...
2
by: iDesmet | last post by:
Hallo, I have 2 forms. In one form (let's call it frmClient) I have textboxes, comboboxes, etc in which I can save/update information to a database (MySQL to be more exactly). The other form...
2
by: erbear | last post by:
Hi all, I am new to VB, and I am having some troubles. I have a listbox that when you click on the item it displays a picture in a picture box and a message in a label. It works fine when an item...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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,...

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.