Hi,
I have written a VB.NET program which successfully sets the backcolor to either LightGreen or LightCoral for a Listbox item which is reliant on a condition statement.
The issue i am having is say that the first item to be added to the listbox meets the LightGreen criteria it gets added with the correct backcolor but when the next item to be added meets the Lightcoral criteria it overwrites the color of the first listbox item also instead of just its backcolor.
Is there away to set each items backcolor so that it keeps its backcolor and as each additional item is added this does not also alter the color of the other items?
I am using the below code
The condition statement is basically like this
SendAsPermission is a string type.
Thanks in advance.
I have written a VB.NET program which successfully sets the backcolor to either LightGreen or LightCoral for a Listbox item which is reliant on a condition statement.
The issue i am having is say that the first item to be added to the listbox meets the LightGreen criteria it gets added with the correct backcolor but when the next item to be added meets the Lightcoral criteria it overwrites the color of the first listbox item also instead of just its backcolor.
Is there away to set each items backcolor so that it keeps its backcolor and as each additional item is added this does not also alter the color of the other items?
I am using the below code
VB.NET:
Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles SRESGroupList.DrawItem
e.DrawBackground()
If (e.State And DrawItemState.None) = DrawItemState.None Then
e.Graphics.FillRectangle(HiLiteBrush, e.Bounds)
End If
Using b As New SolidBrush(e.ForeColor)
e.Graphics.DrawString(SRESGroupList.GetItemText(SRESGroupList.Items(e.Index)), e.Font, b, e.Bounds)
End Using
e.DrawFocusRectangle()
End Sub
The condition statement is basically like this
VB.NET:
If SendAsPermission.Contains("S-RES") = True Then
HiLiteBrush.Color = Color.LightGreen
Else
HiLiteBrush.Color = Color.LightCoral
End If
SendAsPermission is a string type.
Thanks in advance.
Last edited: