tommyready
Member
- Joined
- Jul 1, 2009
- Messages
- 23
- Programming Experience
- 3-5
I'm trying to figure out how to change the background color of a combo box for every item in the selection.
Here is the code I tried:
This method seems to set the whole combo box back color to whatever the last color was.
The color does not change per item. Can anyone help? I also get an error stating that "Index was out of range"
Here is the code I tried:
VB.NET:
Private Sub FillTeamColorsCombo()
Try
Dim Colors As ArrayList = FillColorArray()
For i = 0 To Colors.Count
cboTeamColor.Items.Add(Colors(i))
cboTeamColor.BackColor = System.Drawing.Color.FromName(Colors(i))
Next
Catch ex As Exception
MsgBox("Error Filling Colors Combo Box: " + ex.ToString)
End Try
End Sub
Public Function FillColorArray() As ArrayList
Dim colorNames As New ArrayList
' Get an array of PropertyInfo objects
' from System.Drawing.Color.
Dim typ As System.Type = GetType(System.Drawing.Color)
Dim aPropInfo As System.Reflection. _
PropertyInfo() = typ.GetProperties
For Each pi As System.Reflection. _
PropertyInfo In aPropInfo
If pi.PropertyType.Name = "Color" _
And pi.Name <> "Transparent" Then
colorNames.Add(pi.Name)
End If
Next
Return colorNames
End Function
This method seems to set the whole combo box back color to whatever the last color was.
The color does not change per item. Can anyone help? I also get an error stating that "Index was out of range"
Last edited: