Loop

  • Thread starter Thread starter cmdolcet69
  • Start date Start date
C

cmdolcet69

I need to loop through a index change event, however whenever i loop
through the first combo box always report back correctly its when i
move to the next combobox, that instead of changing the second combo
box it will change the background of the first combo box.

What im i doing wrong?

For intloop = 0 To cboArraylist.Count - 1
If (CType(cboArraylist(intloop), ComboBox).Text) = "Go"
Then
CType(cboArraylist(intloop), Object).BackColor =
Color.LawnGreen
ElseIf (CType(cboArraylist(intloop), ComboBox).Text) = "No
Go" Then
CType(cboArraylist(intloop), Object).BackColor =
Color.Tomato
End If

Next
 
cmdolcet69 said:
I need to loop through a index change event, however whenever i loop
through the first combo box always report back correctly its when i
move to the next combobox, that instead of changing the second combo
box it will change the background of the first combo box.

What im i doing wrong?

For intloop = 0 To cboArraylist.Count - 1
If (CType(cboArraylist(intloop), ComboBox).Text) = "Go"
Then
CType(cboArraylist(intloop), Object).BackColor =
Color.LawnGreen
ElseIf (CType(cboArraylist(intloop), ComboBox).Text) =
"No Go" Then
CType(cboArraylist(intloop), Object).BackColor =
Color.Tomato
End If

Next

First, you should enable Option Strict. I can not compile your code because
the Object data type does not have a BackColor property.

After correcting the error and creating an executable project, I can not
reproduce the problem. Each Combobox gets it's individual color.

How did you add the comboboxes to the Arraylist? Maybe you added the same
Combobox multiple times.


Armin
 
My guess is that the problem is in your ArrayList. Why don't you show us the
code that loads the list. Also, may I suggest...

Dim cbo as ComboBox
For intloop = 0 To cboArraylist.Count - 1
cbo = CType(cboArraylist(intloop), ComboBox)
if cbo.Text = "Go" then
cbo.BackColor = Color.LawnGreen
ElseIf cbo.Text = "No Go" then
cbo.BackColor = Color.Tomato
End If
Next

To me, this is much easier to read and is more effecient.
 
cm,

As soon as you change the index, then the index event is thrown. You can use
a switch or what I like more is setting the eventhandler off at the begin
and add it again at the end of your method.

Cor
 
Back
Top