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

Populating Values Based On The Selection

2
I want to create an application where the user select the category in the first list box and automatically list box 2 gets populated with data relating to each category selected in list box one
Apr 4 '13 #1
4 968
vijay6
158 100+
Hey khomo, write 'Selected Index Changed' event for 'listbox1' (listbox1_SelectedIndexChanged). Inside the event get the current selected value of 'listbox1' using 'listbox1.SelectedItem' property after that you can populate items for 'listbox2' from your datasource.
Apr 4 '13 #2
khomo
2
should i put inside the form on the listbox
Apr 8 '13 #3
IronRazer
83 64KB
Here is a simple example. I used 2 listboxes on a new form and instead of a database i used string arrays to hold the data. When you select an item in listbox1 it populates listbox2 with the items that belong to the selected subject. You could also put the (Select Case) in the MouseDown or MouseUp events of the listbox if you want.
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Dim Subjects() As String = {"Cars", "Colors", "Computers"}
  3.     Dim CarItems() As String = {"Chevy", "Ford", "Dodge"}
  4.     Dim ColorItems() As String = {"Green", "Red", "Blue"}
  5.     Dim ComputerItems() As String = {"Dell", "IBM", "HP"}
  6.  
  7.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  8.         ListBox1.Items.AddRange(Subjects)
  9.     End Sub
  10.  
  11.     Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
  12.         ListBox2.Items.Clear()
  13.         Select Case ListBox1.SelectedIndex
  14.             Case 0
  15.                 ListBox2.Items.AddRange(CarItems)
  16.             Case 1
  17.                 ListBox2.Items.AddRange(ColorItems)
  18.             Case 2
  19.                 ListBox2.Items.AddRange(ComputerItems)
  20.         End Select
  21.     End Sub
  22. End Class
  23.  
Apr 8 '13 #4
vijay6
158 100+
Hey khomo, inside the Form load event add the following line.

Expand|Select|Wrap|Line Numbers
  1. listbox1.SelectedIndexChanged += listbox1_SelectedIndexChanged

And then add the following function inside your class.

Expand|Select|Wrap|Line Numbers
  1. Private Sub listbox1_SelectedIndexChanged(sender As Object, e As EventArgs)
  2. Console.WriteLine(listbox1.SelectedItem) // 'listbox1.selectedItem' property have the value of the selected item in listbox1
  3. // Now connect to your database and retrive all the records which are related to the selected item in listbox1 and fetch those values in listbox2
  4. End Sub
Apr 8 '13 #5

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

Similar topics

3
by: Sharon | last post by:
Hi y'all, I'm trying to figure out how to tackle this problem: I have an XML table with a cool grid in which users can select a table row. When they right-click on a cell, they get a modal dialog...
3
by: sao | last post by:
I am currently using Access 2000. In my table it is the following fields that are set up: 1 - Staff Name 2 - Department This table is already populated with 100+ records (staff along with...
3
by: rmputnam | last post by:
I have a new patient table (PatTbl) that lists Acct, Last, First, among other fields. I need another table listing referring information (RefTbl). My goal is to enter the Acct number in the...
2
by: Randy | last post by:
Hi, I'm trying to populate textbox values upon a change in a combobox selection. I'm using the Publishers table in the Pubs sample database as a simplified example. Here is the code: Private...
2
by: megahurtz | last post by:
This isn't necessarily specific to PHP, but I am trying to figure out a way to pseudo-randomly generate a number based on the month. To clarify a little, I want the number returned to stay the same...
0
by: frankiefrank | last post by:
Hello, I have an aspx page with a RadioButtonList that has two Items, and a "ComboBox" (DropDownList) that I want to populate based on the selection in the RadioButtonList. The first...
3
by: Hodld | last post by:
Hi, I'm creating a selection form with array data, using a for loop. This is my first time doing this, so it could be a pretty dumb mistake, but all the values end up printing on the line above...
7
by: LSGKelly | last post by:
I am working on a query that I would like to get the top 4 values based on a group. Here is the SQL: SELECT qRenPercRept1.CountOfccName, qRenPercRept1.Merged, qRenPercRept1.ccName,...
2
David Blackman
by: David Blackman | last post by:
I have a form with 4 unbound listboxes (LB). When the form opens, I want: 1. LB1 to display values in row 1; 2. LB3 to display data based on the value of LB1; 3. LB4 to display data based...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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?
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
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.