Home All Groups Group Topic Archive Search About
Author
20 Nov 2007 6:31 PM
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

Author
20 Nov 2007 7:28 PM
Armin Zingler
Show quote Hide quote
"cmdolcet69" <colin_dolce***@hotmail.com> schrieb
> 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
Author
20 Nov 2007 7:46 PM
Terry
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.

--
Terry


Show quoteHide quote
"cmdolcet69" wrote:

> 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
>
Author
20 Nov 2007 8:01 PM
Cor Ligthert[MVP]
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