-
[2005] List1 selected items
Hi guys,
I have bit trouble with the code, I have two comboboxes with list1 and I am trying to block the code to stop them passing with other code and go to the wrong way around. When I selected the first item on combobox1, the setselected moved to item2 on list1. I am trying to stick the code on combobox1 with the first item on the list1 when I select any of items from combobox1 and hope for the return when I do on combobox2 to go with second item on list1.
Here it the code:
Code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem = "Item1" Then
List1.Items.Clear()
List1.Items.Add(My.Resources.RuntimeStrings_test.1)
List1.Items.Add(My.Resources.RuntimeStrings_test.2)
If Me.ComboBox1.Items.Count > 0 Then List1.SetSelected(0, True)
End If
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem = "Item2" Then
List1.Items.Clear()
List1.Items.Add(My.Resources.RuntimeStrings_test.1)
List1.Items.Add(My.Resources.RuntimeStrings_test.2)
If Me.ComboBox1.Items.Count > 1 Then List1.SetSelected(1, True)
End If
End Sub
I have also tried this
Code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem = "Item1" Then
List1.Items.Clear()
List1.Items.Add(My.Resources.RuntimeStrings_test.1)
List1.Items.Add(My.Resources.RuntimeStrings_test.2)
If ComboBox1.SelectedItem.Count = 0 Then List1.SetSelected(0, True)
End If
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem = "Item2" Then
List1.Items.Clear()
List1.Items.Add(My.Resources.RuntimeStrings_test.1)
List1.Items.Add(My.Resources.RuntimeStrings_test.2)
If ComboBox2.SelectedItem.Count = 1 Then List1.SetSelected(1, True)
End If
End Sub
It didn't works :(
I am trying to make the code in separate but they are making like a loop and I have no where to make it go different.
Hope you guys can help me with this.
Thanks,
Mark
-
Re: [2005] List1 selected items
-
Re: [2005] List1 selected items
I'm sorry but I don't understand the description of the problem at all.
Why do you have two selectedIndex change events handling Combobox1.SelectedIndexChanged ???
If you look at the end you will see that they both handle the same thing. It doesn't make any sense.
-
Re: [2005] List1 selected items
It's not the two same selectedIndex. I'm using two different selectedIndex. When I selected each of those items on two comboboxes, like combobox1. It direct me to the wrong item on list1 which I am trying to force any of items on combobox1 to selecting the first item on list1. But any items from combobox1 that I select with, went to the wrong item on list1. So it the same for combobox2 when I select any of those items and it selected the wrong item on list1.
How could I block the code in order to stop them passing to each of those lines and do the wrong job??
You can see the code below:
Code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem = "Item1" Then
List1.Items.Clear()
List1.Items.Add(My.Resources.RuntimeStrings_test.1)
List1.Items.Add(My.Resources.RuntimeStrings_test.2)
If Me.ComboBox1.Items.Count > 0 Then List1.SetSelected(0, True)
End If
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
If ComboBox1.SelectedItem = "Item2" Then
List1.Items.Clear()
List1.Items.Add(My.Resources.RuntimeStrings_test.1)
List1.Items.Add(My.Resources.RuntimeStrings_test.2)
If Me.ComboBox1.Items.Count > 1 Then List1.SetSelected(1, True)
End If
End Sub
I want to select any of those items from combobox1 to select the first item on list1 for themself so it the same for combobox2, when I select any of those items on combobox2 to select the second item on list1.
Hope this is clear to you what I am trying to do.
Thanks,
Mark
Quote:
Originally Posted by stimbo
I'm sorry but I don't understand the description of the problem at all.
Why do you have two selectedIndex change events handling Combobox1.SelectedIndexChanged ???
If you look at the end you will see that they both handle the same thing. It doesn't make any sense.
-
Re: [2005] List1 selected items
anyone who know how to solve this problem??
Thanks,
Mark
-
Re: [2005] List1 selected items
By the sounds of it, you say it works, but doesn't give the right value.
From what I see, it seems the two if's have different Count and Value. COuld this be your problem?
Code:
If Me.ComboBox1.Items.Count > 0 Then List1.SetSelected(0, True)
If Me.ComboBox1.Items.Count > 1 Then List1.SetSelected(1, True)
-
Re: [2005] List1 selected items
I have tried it already but if I add another combobox which it combobox2, then it will get the loops will get pass each of those lines. I need to block the loops to stop them passing each of those lines.
Code:
If Me.ComboBox1.Items.Count > 0 Then List1.SetSelected(0, True)
If Me.ComboBox1.Items.Count > 1 Then List1.SetSelected(1, True)
If Me.ComboBox2.Items.Count > 1 Then List1.SetSelected(2, True)
How I could block the loops to stop them running each of those lines on the code that show on above??
Thanks,
Mark
Quote:
Originally Posted by TURKINATOR
By the sounds of it, you say it works, but doesn't give the right value.
From what I see, it seems the two if's have different Count and Value. COuld this be your problem?
Code:
If Me.ComboBox1.Items.Count > 0 Then List1.SetSelected(0, True)
If Me.ComboBox1.Items.Count > 1 Then List1.SetSelected(1, True)
-
Re: [2005] List1 selected items
Add these debug statements.
Code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
debug.writeline (ComboBox1.SelectedItem)
If ComboBox1.SelectedItem = "Item1" Then
...
End Sub
Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
debug.writeline (ComboBox1.SelectedItem)
If ComboBox1.SelectedItem = "Item2" Then 'ComboBox1?????
...
End Sub
Also, what is List1?
-
Re: [2005] List1 selected items
List1 is a listbox, where I want to have relate with combobox1 and combobox2, also I have forgot to included with button1 where I am trying to have relationship with them. I have trouble with the loop that when I selected the item on combobox1 "Item1" and I click on button1, I make the items clear on list1 and add the items again which the selected index on list1 stay on the first item to selected so when I selected the second item on combobox2 "Item2" and click the button, the selected index on list1 should have stay on the second item but they return to the first item on list1. I am trying to block the loop in order to stop them getting pass in each of those lines but there are no way that I can do to get it working out. :(
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
You can see two different combobox between 1 and 2 at the end, also it included with ListBox1.SelectedIndex. I have tried hundred of times to find a way to get the loop to blocking but they keep passing in each of those lines and do the wrong things.
Hope you can help me as I tried to block the loops but it didn't work for me out that way.
Thanks,
Mark
-
Re: [2005] List1 selected items
After this line
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
add these
debug.writeline (ComboBox1.SelectedItem)
debug.writeline (ComboBox2.SelectedItem)
run your code and then tell me the output from the immediate window (where the debug output is).
One time I look at your code and it is in one handler, then it is in another handler. Let's go slow, a few changes at a time.
Your english is better than my (whatever your native language is), but you are very, very, very, hard to understand.
-
Re: [2005] List1 selected items
Well, just try and understand little bit harder what I am trying to do and you may get it. I am not at that good with my english so I am trying my best ;)
Thanks
Mark
-
Re: [2005] List1 selected items
I am trying hard, believe me. So what was the output from the debug?
-
Re: [2005] List1 selected items
Ok, tell me which one of them you might get it?? And what do you mean by "what was the output from the debug?"??
If you means how did they went, I would like to tell that the output debug are doing the same things where it was :(
Hope you know what to do to help me out if you get what I am trying to do.
Thanks,
Mark
-
Re: [2005] List1 selected items
I am trying, but I asked you to tell me what the ouput from the debug was, not your opinion of what it was.
Also, before button1click what values are in:
combobox1
combobox2
list1
What I expect from you is this
The output from debug.writeline (ComboBox1.SelectedItem) is _________
The output from debug.writeline (ComboBox2.SelectedItem) is__________
combox1 contains
__________
_________
_________
etc.
combox2 contains
__________
_________
_________
etc.
listbox1 contains
__________
_________
_________
etc.
And the same thing for what they should look like after the button is clicked.
-
Re: [2005] List1 selected items
I don't really get it what you are trying to say and tell me what to do. Can you discuss me a little more with an example code plz??
Thanks,
Mark
-
Re: [2005] List1 selected items
Maybe if I color code it that will help. I am asking you to tell me the ACTUAL DATA at specific points and times using YOUR button click code.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
debug.writeline (ComboBox1.SelectedItem)
debug.writeline (ComboBox2.SelectedItem)
'NOTE A
If Me.ComboBox1.SelectedItem = "Item1" Then
The output from debug.writeline (ComboBox1.SelectedItem) is _________
The output from debug.writeline (ComboBox2.SelectedItem) is__________
NOTE A - when we get to NOTE B what does:
> combox1 contain?
__________
_________
_________
etc.
> combox2 contain?
__________
_________
_________
etc.
> listbox1 contain?
__________
_________
_________
After ALL of the code for
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
...
End Sub 'NOTE B
executes what SHOULD the comboboxes look like?
NOTE B - when we get to NOTE B what does:
> combox1 contain?
__________
_________
_________
etc.
> combox2 contain?
__________
_________
_________
etc.
> listbox1 contain?
__________
_________
_________
I don't know how to be more plain.
-
Re: [2005] List1 selected items
-
Re: [2005] List1 selected items
Without information it is hard to help. Here is your code slightly modified. Copy and paste it, all of it. Then re-create the problem and copy and paste the immediate window when it stops. edit-> Then re-create the problem and copy and paste the immediate window when it stops.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Debug.WriteLine("TEST " & Date.Now.ToLongTimeString)
Debug.WriteLine(ComboBox1.SelectedItem & " C1 " & ComboBox1.SelectedIndex)
Debug.WriteLine(ComboBox2.SelectedItem & " C2 " & ComboBox2.SelectedIndex)
For Ctr As Integer = 0 To ComboBox1.Items.Count - 1
Debug.WriteLine(ComboB.Items.Item(Ctr) & " 1c" & Ctr)
Next
For Ctr As Integer = 0 To ComboBox2.Items.Count - 1
Debug.WriteLine(ComboBox2.Items.Item(Ctr) & " 2c" & Ctr)
Next
For Ctr As Integer = 0 To List1.Items.Count - 1
Debug.WriteLine(List1.Items.Item(Ctr) & " L" & Ctr)
Next
'your code
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 your code
Debug.WriteLine(ComboBox1.SelectedItem & " C1 " & ComboBox1.SelectedIndex)
Debug.WriteLine(ComboBox2.SelectedItem & " C2 " & ComboBox2.SelectedIndex)
For Ctr As Integer = 0 To ComboBox1.Items.Count - 1
Debug.WriteLine(ComboB.Items.Item(Ctr) & " 1c" & Ctr)
Next
For Ctr As Integer = 0 To ComboBox2.Items.Count - 1
Debug.WriteLine(ComboBox2.Items.Item(Ctr) & " 2c" & Ctr)
Next
For Ctr As Integer = 0 To List1.Items.Count - 1
Debug.WriteLine(List1.Items.Item(Ctr) & " L" & Ctr)
Next
Debug.WriteLine("END " & Date.Now.ToLongTimeString)
Stop 'go to the immediate window and copy the output
End Sub
-
Re: [2005] List1 selected items
Thanks, I have pasted the code and input on my form but unfortunately it's the still the same where it was :(
What I am trying to do is 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 item "Item2" from combobox2 and press button1, it suppose to be the selected the second item on list1 to get selected but when I press the button1, it return to the first item on list1.
On my following code where I am on now, it keep going on the wrong way around like loops and I cannot find a way to block it.
Hope you have the experience that will show me how to block the loops.
Thanks,
Mark
-
Re: [2005] List1 selected items
I editied my previous post. Please look at it carefully.
-
Re: [2005] List1 selected items
You have done it wrong, that is NOT what I am trying to do. Please read my post again carefully...
What I am trying to do is 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 item "Item2" from combobox2 and press button1, it suppose to be the selected the second item on list1 to get selected but when I press the button1, it return to the first item on list1.
On my following code where I am on now, it keep going on the wrong way around like loops and I cannot find a way to block it.
Hope you have the experience that will show me how to block the loops.
Thanks,
Mark
-
Re: [2005] List1 selected items
Let me see......... nope, can't read your mind. What was the error exactly and where exactly was the error.
-
Re: [2005] List1 selected items
I copied your button code exactly. Don't tell me I did it wrong.:mad:
-
Re: [2005] List1 selected items
Your code posting is making like a loops, the same problem as I has. There is no way we can find it to block it. Hopefully someone out there can help me with different way of doing this.
Thanks in advance.
Mark
-
Re: [2005] List1 selected items
I am done! Since post #10 I have been trying to get information from you. I even wrote the debug statements. All you had to do was copy and paste the output from the debug statements.
Why couldn't you do that?
-
Re: [2005] List1 selected items
I have copied and pasted, didn't work that way. And this is NOT the one I wanted. You wrote the wrong code which you have following the wrong instructions, please read my post again ffs :mad:
Thanks,
Mark
Quote:
Originally Posted by dbasnett
I am done! Since post #10 I have been trying to get information from you. I even wrote the debug statements. All you had to do was copy and paste the output from the debug statements.
Why couldn't you do that?
-
Re: [2005] List1 selected items
Quote:
Originally Posted by Mark103
I have copied and pasted, didn't work that way.
See Post#22 where you ignored another question.
Quote:
Originally Posted by Mark103
And this is NOT the one I wanted. You wrote the wrong code which you have following the wrong instructions, please read my post again ffs :mad:
I assumed that the last piece of code you posted was the latest. You've done that in other threads, provide code, then some different code, and we are left to read your mind.
-
Re: [2005] List1 selected items
Mark, this forum is for programmers to help each other, not for supplying services. If you would like to hire a programmer to write code for you, there are other places where you can go to do that (such as our Jobs forums).
Everyone needs to take a step back, a few deep breaths, and cool down. Some of you have already been warned against aggressive behaviour very recently. If there is any more, we will start to consider banning people from the forums.
-
Re: [2005] List1 selected items
I know that but that guy gave me the bug which it will NOT solve my problem. It still the same where I was, see my 9th post. :rolleyes:
I have keep telling him to read my post again but he said that is the fixed code which it hasn't. It still the same what that guy gave me, it's BUG and it will do nothing to fix my own problem :mad:
Quote:
Originally Posted by penagate
Mark, this forum is for programmers to help each other, not for supplying services. If you would like to hire a programmer to write code for you, there are other places where you can go to do that (such as our Jobs forums).
Everyone needs to take a step back, a few deep breaths, and cool down. Some of you have already been warned against aggressive behaviour very recently. If there is any more, we will start to consider banning people from the forums.
-
Re: [2005] List1 selected items
I understand that, but criticising people who are trying their best to help you isn't on.
-
Re: [2005] List1 selected items
You chose to post on an English speaking Forum. It is your responsibility to be clear. I wouldn't go to a Spanish forum and get angry because they didn't understand me. I am trying to eliminate the language barrier.
Because I think this is a language issue I am going to try one more time with RULES.
Mark - if you want my help here are the RULES.
1. Do ONLY what I ask.
2. No comments or opinions.
3. Provide exactly what I ask, nothing more or LESS.
4. Read the rules again.
Step 1
Mark - copy and paste the code you want to fix. If the post contains anything but code you are on your own.
-
Re: [2005] List1 selected items
here it is
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
I want to use one button only, not two.
Thanks,
Mark
-
Re: [2005] List1 selected items
I will look at it when I get home. Should be a couple of hours.
-
Re: [2005] List1 selected items
1-Replace your button 1 code with the following code.
2-re-create the problem.
3-the stop command in the new button1 code will take you to the debugger.
4-when it does go to the immediate window and copy from the line that contains 'start copy' through the line that contains 'end copy'.
5-Paste the result here.
6-IF there is an error message I will need to know which line and which error exactly.
7-How and where is this My.Resources.RuntimeStrings_test.1
and this My.Resources.RuntimeStrings_test.2
defined? I have them commented out for the moment.
7a-Do you have two listboxes? List1 and ListBox1?
8-See the end of this post for a sample of what I want to see
9-remember the rules!!!
10-remember the rules!!!
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Debug.WriteLine(vbCrLf & vbCrLf & "TEST- start copy " & Date.Now.ToLongTimeString)
Debug.WriteLine(ComboBox1.SelectedItem & " C1 " & ComboBox1.SelectedIndex)
Debug.WriteLine(ComboBox2.SelectedItem & " C2 " & ComboBox2.SelectedIndex)
For Ctr As Integer = 0 To ComboBox1.Items.Count - 1
Debug.WriteLine(ComboBox1.Items.Item(Ctr) & " 1c " & Ctr)
Next
For Ctr As Integer = 0 To ComboBox2.Items.Count - 1
Debug.WriteLine(ComboBox2.Items.Item(Ctr) & " 2c " & Ctr)
Next
For Ctr As Integer = 0 To List1.Items.Count - 1
Debug.WriteLine(List1.Items.Item(Ctr) & " L " & Ctr)
Next
For Ctr As Integer = 0 To ListBox1.Items.Count - 1
Debug.WriteLine(ListBox1.Items.Item(Ctr) & " LB " & Ctr)
Next
'start original code
If Me.ComboBox1.SelectedItem = "Item1" Then
List1.Items.Clear() '??? List1 or ListBox1 or are they two different ListBoxes
' how and where is this My.Resources.RuntimeStrings_test.1 defined?
'List1.Items.Add(My.Resources.RuntimeStrings_test.1) 'i had to change this here and in the resource
'List1.Items.Add(My.Resources.RuntimeStrings_test.2) 'i had to change this here and in the resource
ListBox1.SelectedIndex = 0
End If
If Me.ComboBox2.SelectedItem = "Item2" Then
ListBox1.SelectedIndex = 1 '??? List1 or ListBox1 or are they two different ListBoxes
End If
Me.But1.Enabled = False '???
'end original code
Debug.WriteLine(ComboBox1.SelectedItem & " C1 " & ComboBox1.SelectedIndex)
Debug.WriteLine(ComboBox2.SelectedItem & " C2 " & ComboBox2.SelectedIndex)
For Ctr As Integer = 0 To ComboBox1.Items.Count - 1
Debug.WriteLine(ComboBox1.Items.Item(Ctr) & " 1c " & Ctr)
Next
For Ctr As Integer = 0 To ComboBox2.Items.Count - 1
Debug.WriteLine(ComboBox2.Items.Item(Ctr) & " 2c " & Ctr)
Next
For Ctr As Integer = 0 To List1.Items.Count - 1
Debug.WriteLine(List1.Items.Item(Ctr) & " L " & Ctr)
Next
For Ctr As Integer = 0 To ListBox1.Items.Count - 1
Debug.WriteLine(ListBox1.Items.Item(Ctr) & " LB " & Ctr)
Next
Debug.WriteLine("END TEST - end copy " & Date.Now.ToLongTimeString)
Stop 'this cause the program to stop and should take you to the debugger
End Sub
SAMPLE OUTPUT
TEST- start copy 12:48:15 PM
C1 -1
C2 -1
one 1c 0
two 1c 1
three 2c 0
four 2c 1
l1 1 L 0
l1 2 L 1
lb1 1 LB 0
lb1 2 LB 1
lb1 3 LB 2
C1 -1
C2 -1
one 1c 0
two 1c 1
three 2c 0
four 2c 1
l1 1 L 0
l1 2 L 1
lb1 1 LB 0
lb1 2 LB 1
lb1 3 LB 2
END TEST - end copy 12:48:15 PM
-
Re: [2005] List1 selected items
I copied and pasted your code on my form. I checked with the controls and it is still the SAME where it was. No different. Check you code again plz or I want someone else to help me to get the job done, plz dont waste my time!!!!!!!!!!!
Regards,
Mark
-
Re: [2005] List1 selected items
Did you do all the other steps as well as copy and paste?
-
Re: [2005] List1 selected items
I copied and pasted your code on my form. yes
I checked with the controls and it is still the SAME where it was. - i didn't ask for this, and specifically said i didn't want it
No different. - since we hadn't got to the figuring out part i expected it. i was trying to get information so i could figure it out.
Check you code again plz - Not no, but hell no.
or I want someone else to help me to get the job done - good luck finding someone to put up with you.
plz dont waste my time!!!!!!!!!!! - that is about the funniest statement i have ever heard. :mad: and don't worry i won't. YOU JUST COULDN'T DO WHAT I ASKED AND SEE WHERE IT LED, YOU ARE A PIECE OF WORK.
-
Re: [2005] List1 selected items
Yes I did, I have done everything I could do but that idiot is trying to waste my time, plus trying to be funny with me. I am not stupid, he is stupid enough to know what I wanted so he couldn't be bother to help. He's bell-end.....
He suppose to help but he is keepin annoying me, spamming the forum and time wasters :mad: :mad: :mad: :mad: :mad: :mad: :mad:
Quote:
Originally Posted by penagate
Did you do all the other steps as well as copy and paste?
-
Re: [2005] List1 selected items
Again I stress: This forum is for technical help and discussion, not for making personal attacks. Members who cannot abide by some simple and straight-forward rules will be expelled from the community.
This thread is now closed due to the inability of participants to conduct themselves in a mature and respectful manner.