Listbox DrawItem question

S

SStory

I have a listbox and I am drawing my items.

For some reason the selected item doesn't show a selection....

this seems to happen even if I tell it to draw focus rectangle.

What should I do to so a selected item?

Thanks,

Shane
 
B

BluDog

I have a listbox and I am drawing my items.

For some reason the selected item doesn't show a selection....

this seems to happen even if I tell it to draw focus rectangle.

What should I do to so a selected item?

Thanks,

Shane

Can you post the code from your DrawItem sub please.
 
K

Ken Tucker [MVP]

Hi,

Dim dsXML As New DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

dsXML.ReadXml("http://msdn.microsoft.com/rss.xml")

dsXML.WriteXml("rss.xml")

ListBox1.DataSource = dsXML.Tables("item")

ListBox1.DisplayMember = "pubDate"

ListBox1.DrawMode = DrawMode.OwnerDrawFixed

End Sub

Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem

Dim g As Graphics = e.Graphics

Dim dr As DataRowView

Dim dt As Date

Dim br As SolidBrush

Dim s As String

Dim dtCompare As Date = #6/18/2004#

Try

dr = DirectCast(ListBox1.Items.Item(e.Index), DataRowView)

dt = Date.Parse(dr.Item("pubDate").ToString)

s = dt.ToShortDateString

Catch ex As Exception

Trace.WriteLine(ex.ToString)

End Try

g.FillRectangle(Brushes.White, e.Bounds)

If CBool(e.State And DrawItemState.Selected) Then

g.FillRectangle(Brushes.LightBlue, e.Bounds)

End If

If dt < dtCompare Then

br = New SolidBrush(Color.Red)

Else

br = New SolidBrush(Color.Black)

End If

g.DrawString(s, ListBox1.Font, br, _

RectangleF.op_Implicit(e.Bounds))

br.Dispose()

End Sub



Ken
 
S

SStory

Ok... so I do have to draw it myself? That was the way I was attempting to
do it.

What does the drawfocus rectangle do then?

Thanks,

Shane
 
S

SStory

BluDog,

I think according to Ken, I must manually draw it... It thought there might
be some other thing like drawfocusrectangle....

If I just need to draw it then I can do that.

Thanks,

Shane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top