Try something like the following.
Private DataTable1 As DataTable
....
DataTable1 = New DataTable("MyTa ble")
DataTable1.Colu mns.Add("ID", Type.GetType("S ystem.String"))
DataTable1.Colu mns.Add("Name", Type.GetType("S ystem.String"))
DataTable1.Colu mns.Add("Catego ry", Type.GetType("S ystem.Int32"))
Dim rand As New Random
Dim iterator As Integer
For iterator = 0 To 25
DataTable1.Rows .Add(New Object() {Guid.NewGuid() .ToString(), "Name" +
iterator.ToStri ng(), rand.Next(0, 4).ToString()})
Next
Me.ListBox1.Dis playMember = "Name"
Me.ListBox1.Val ueMember = "ID"
Me.ListBox1.Dat aSource = DataTable1.Defa ultView
....
Private Sub ListBox1_DrawIt em(ByVal sender As Object, ByVal e As
System.Windows. Forms.DrawItemE ventArgs) Handles ListBox1.DrawIt em
Dim list As ListBox = DirectCast(send er, ListBox)
Dim row As DataRow = DirectCast(list .Items(e.Index) , DataRowView).Ro w
Dim textBrush As Brush
e.DrawBackgroun d()
Select Case (DirectCast(row ("Category") , Integer))
Case 0
textBrush = Brushes.Red
Case 1
textBrush = Brushes.Green
Case 2
textBrush = Brushes.Blue
Case 3
textBrush = Brushes.Orange
End Select
e.Graphics.Draw String(DirectCa st(row("Name"), String), list.Font,
textBrush, New RectangleF(e.Bo unds.X, e.Bounds.Y, e.Bounds.Width,
e.Bounds.Height ))
e.DrawFocusRect angle()
End Sub
--
Tim Wilson
..Net Compact Framework MVP
"Richard Wilde" <ri*****@yahoo. com> wrote in message
news:ue******** *****@TK2MSFTNG P15.phx.gbl...
I am trying to change a colour of a listbox item depending on a value in a
data view
My fields in the dataview are
ID
Name
idCat
ListBox1.ValueM ember = "ID"
ListBox1.DataSo urce = dv1
ListBox1.Displa yMember = "Name"
I have set the listbox drawMode to OwnerdrawFixed and want to be able to
display the name in a different color depending on the idCat. This is
where i have run into problems. I cannot retrieve the idCat from any of the pass
ed in parameters... Can any one help?
DrawItem event...
dim idCat as int32
idCat = <<HERE>>
Select Case (e.Index)
Case 0
myBrush = Brushes.Red
Case 1
myBrush = Brushes.Orange
Case 2
myBrush = Brushes.Purple
End Select
draw...