Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,557 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,920 people online right now. Registration is fast and FREE... Join Now!




Listbox1 changes selected index problem

 
Reply to this topicStart new topic

Listbox1 changes selected index problem, problem of trying to block loops

mark103
13 Apr, 2008 - 12:02 PM
Post #1

New D.I.C Head
*

Joined: 13 Apr, 2008
Posts: 2

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:

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!
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Listbox1 Changes Selected Index Problem
13 Apr, 2008 - 04:41 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,997



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Moved to VB.Net smile.gif
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Listbox1 Changes Selected Index Problem
13 Apr, 2008 - 05:15 PM
Post #3

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,947



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
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?

User is offlineProfile CardPM
+Quote Post

mark103
RE: Listbox1 Changes Selected Index Problem
13 Apr, 2008 - 06:04 PM
Post #4

New D.I.C Head
*

Joined: 13 Apr, 2008
Posts: 2

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 mad.gif



Hope you could help me out


thanks
mark

QUOTE(jayman9 @ 13 Apr, 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?


User is offlineProfile CardPM
+Quote Post

Jayman
RE: Listbox1 Changes Selected Index Problem
13 Apr, 2008 - 07:22 PM
Post #5

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,947



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
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.
.
.

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 11:24PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month