Listbox1 changes selected index problem

problem of trying to block loops

Page 1 of 1

4 Replies - 4531 Views - Last Post: 13 April 2008 - 08:22 PM Rate Topic: -----

#1 mark103  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 107
  • Joined: 13-April 08

Listbox1 changes selected index problem

Post icon  Posted 13 April 2008 - 01:02 PM

Hi guys

I have problem with listbox. When I selected the item "Item1" from combobox1, then press button1 to clear and add the items on list1. Then make the first item on list1 to get selected. So after that I selected the second item on selected index on my list1 then selected the item "Item2" from combobox2 and press button1 without clear or add any items, it suppose to be selected the second item on list1 to get selected but when I press the button1, it return to the first item on list1.


Here it the code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

		If Me.ComboBox1.SelectedItem = "Item1" Then
			List1.Items.Clear()
			List1.Items.Add(My.Resources.RuntimeStrings_test.1)
			List1.Items.Add(My.Resources.RuntimeStrings_test.2)
			ListBox1.SelectedIndex = 0
		End If


		If Me.ComboBox2.SelectedItem = "Item2" Then 
			ListBox1.SelectedIndex = 1
		End If
		Me.Button1.Enabled = False
	End Sub






How I can stop the loops returning to selected index one whens when I selected "item2" from combobox2 and click the button1??



Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Listbox1 changes selected index problem

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Listbox1 changes selected index problem

Posted 13 April 2008 - 05:41 PM

Moved to VB.Net :)
Was This Post Helpful? 0
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 421
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Listbox1 changes selected index problem

Posted 13 April 2008 - 06:15 PM

Hmmm, to be honest I am not at all sure what you just said. But I think you are looking for a way to set the selected item in the ListBox to the item that is selected in the ComboBox. Is that correct?

Do they both have the same name or can you only reference it by the Index number in your ListBox?
Was This Post Helpful? 0
  • +
  • -

#4 mark103  Icon User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 107
  • Joined: 13-April 08

Re: Listbox1 changes selected index problem

Posted 13 April 2008 - 07:04 PM

Yeah, but both have different name on it so I am trying to reference by the index number in my listbox. I have difficulty because of the loops :angry:



Hope you could help me out


thanks
mark

View Postjayman9, on 13 Apr, 2008 - 06:15 PM, said:

Hmmm, to be honest I am not at all sure what you just said. But I think you are looking for a way to set the selected item in the ListBox to the item that is selected in the ComboBox. Is that correct?

Do they both have the same name or can you only reference it by the Index number in your ListBox?

Was This Post Helpful? 0
  • +
  • -

#5 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 421
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Listbox1 changes selected index problem

Posted 13 April 2008 - 08:22 PM

Loops? Is there more code you have not shown us yet?

There isn't any loops in the code you provided.

Now I am even more confused. Can you explain in detail exactly what you want to happen?

List the events in order of sequence. Like the example I provided below.

Example:
1. Select item in ComboBox
2. Click button to add to Listbox
3. Item in ListBox is selected
etc.
.
.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1