Combo Box to List Boxes in VB

Make a selection from a Combo Box populate to List Boxes

Page 1 of 1

3 Replies - 4533 Views - Last Post: 01 December 2009 - 11:03 AM Rate Topic: -----

#1 rhorst  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-November 09

Combo Box to List Boxes in VB

Post icon  Posted 30 November 2009 - 12:34 PM

I am a beginner and am trying to create a WPF browser application that allows you to search and display recipes. The combo box presents choices, the Ingredients display in one list box and the "cooking" instructions appear in the other list box. What's happening is the first time you make a selection from the combobox nothing displays, and this could be happening because the first line of code under Selectionchanged clears the List Boxes however, it should be populating those list boxes with content, shouldn't it? Anyway, as you make other selections List boxes 1 & 2 get populated but they do not match what displays in the Combo box, i.e. if you select "Easy Taco Dip" any random recipe might appear in List Boxes 1 & 2. I'm confused! I've only included a couple of examples for brevity.

Thanks,
Rose


Option Explicit On
Class Page1
	'User Makes a selection from the ComboBox which populates List Boxes 1 & 2

	Private Sub ComboBox1_Selectionchanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionchangedEventArgs) Handles ComboBox1.Selectionchanged
		'Clears both List Boxes as the selection in the ComboBox is changed
		ListBox1.Items.Clear()
		ListBox2.Items.Clear()

		Select Case ComboBox1.Text

			Case "Easy Taco Dip"
				ListBox1.Items.Add("1-1/2 cups MIRACLE WHIP® Dressing")
				ListBox1.Items.Add("1-1/2 cups  BREAKSTONE'S® or KNUDSEN® Sour Cream")
				ListBox1.Items.Add("1 pkg. 1-1/4 oz. TACO BELL® HOME ORIGINALS® Taco Seasoning Mix")
				ListBox2.Items.Add("MIX all ingredients until well blended; cover.")
				ListBox2.Items.Add("Refrigerate several hours or until chilled.")
				ListBox2.Items.Add("Serve with cut-up fresh vegetables or assorted chips.")

			Case "O-So-Easy Cheese Log"
				ListBox1.Items.Add("1 pkg. (8 oz.) PHILADELPHIA® Cream Cheese, softened")
				ListBox1.Items.Add("1 cup  KRAFT 2% Milk Shredded Italian* Three Cheese Blend ")
				ListBox1.Items.Add("1 pkt. (1 oz.) dry onion soup mix")
				ListBox1.Items.Add("2 Tbsp.  BREAKSTONE'S® Reduced Fat or KNUDSEN® Light Sour Cream")
				ListBox1.Items.Add("2/3 cup finely chopped PLANTERS® Pecans, toasted")
				ListBox2.Items.Add("MIX first 4 ingredients.")
				ListBox2.Items.Add("SHAPE into log; wrap in plastic wrap. Refrigerate 2 hours.")
				ListBox2.Items.Add("UNWRAP log; roll in nuts. Firmly press nuts into log to secure.")
				ListBox2.Items.Add("Serve with RITZ® Crackers and grapes.")
End Select
	End Sub

	'Combo Box choices are added at Page load event.

	Private Sub Page1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded

		ComboBox1.Items.Add("Easy Taco Dip")
		ComboBox1.Items.Add("O-So-Easy Cheese Log")
		ComboBox1.Items.Add("Double Decker Tacos")
		ComboBox1.Items.Add("Italian Meatloaf")
		ComboBox1.Items.Add("Tuna Pasta Salad")
		ComboBox1.Items.Add("Mushroom Rice Salad")
		ComboBox1.Items.Add("Philadelphia® 3-Step Pina Colada Cheesecake")
		ComboBox1.Items.Add("Philadelphia® 3-Step Chocolate Chip Cheesecake")

		'Ensures the ComboBox begins empty
		ComboBox1.SelectedItem = 0

	End Sub

End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Combo Box to List Boxes in VB

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: Combo Box to List Boxes in VB

Posted 30 November 2009 - 01:47 PM

Moved to VB.NET.
Was This Post Helpful? 0
  • +
  • -

#3 sharpy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 35
  • View blog
  • Posts: 394
  • Joined: 02-June 07

Re: Combo Box to List Boxes in VB

Posted 30 November 2009 - 02:23 PM

Hi

I changed this line of code

Private Sub ComboBox1_Selectionchanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionchangedEventArgs) Handles ComboBox1.Selectionchanged



To this

 Private Sub ComboBox1_Selectionchanged(ByVal sender As Object, ByVal e As System.EventArgs) _
  Handles ComboBox1.TextChanged


I tested it and it seem to do what you wanted

Hope this helps
Was This Post Helpful? 0
  • +
  • -

#4 rhorst  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 27-November 09

Re: Combo Box to List Boxes in VB

Posted 01 December 2009 - 11:03 AM

Thanks for your help but here is what I eventually had to do to fix the problem:
Select Case ComboBox1.SelectItem


Thanks again
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1