On Mon, 5 Jul 2004 10:36:59 +0200, "Brett Miller"
<br***@NOSPAMpsion.co.za> wrote:
I need to change the colour of certain items in a listbox depending on
criteria I receive from my dataset? How would this be accomplished?
Add a listbox to a form and try this:
<Code>
Public Sub New()
MyBase.New()
InitializeComponent()
ListBox1.DrawMode = DrawMode.OwnerDrawFixed
ListBox1.Items.Add("Black")
ListBox1.Items.Add("Red")
ListBox1.Items.Add("Green")
ListBox1.Items.Add("Blue")
ListBox1.Items.Add("Pink")
End Sub
Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As
DrawItemEventArgs) Handles ListBox1.DrawItem
Dim s As String = ListBox1.Items(e.Index).ToString
Dim b As New SolidBrush(Color.FromName(s))
e.DrawBackground()
e.DrawFocusRectangle()
e.Graphics.DrawString(s, Font, b, e.Bounds.X, e.Bounds.Y)
b.Dispose
End Sub
</Code>
Hope this helps
Blu