sub item in list view item invalid bounds during DrawItem in owner draw

S

Smokey Grindle

This is just a wierd one... I am trying to draw the sub items in the
drawitem event of the list view in owner drawn mode (because of documented
W32 rendering bugs) instead of in two seperate items drawitem and
drawsubitems... but when I run this code in the drawitems

For Each subItm As ListViewItem.ListViewSubItem In _tn.SubItems

' If subItm..ColumnIndex <> 0 Then

'If (e.State And Windows.Forms.ListViewItemStates.Selected) = 1 Then

' textColor = Drawing.SystemColors.Window

'Else

' textColor = e.Item.ForeColor

'End If

If _tn.SubItems.IndexOf(subItm) > 0 Then

If (e.State And Windows.Forms.ListViewItemStates.Hot) = 0 Then

Debug.WriteLine(String.Format("Left: {0} Index: {1} Text {2}",
subItm.Bounds.Left, _tn.SubItems.IndexOf(subItm), subItm.Text.Trim))

Debug.WriteLine(subItm.Bounds)

e.Graphics.DrawString(subItm.Text, subItm.Font, New
Drawing.SolidBrush(textColor), New Drawing.RectangleF(subItem.Bounds.Left,
subItm.Bounds.Top + ((subItm.Bounds.Height -
CInt(e.Graphics.MeasureString(subItm.Text, subItm.Font).Height)) \ 2),
subItm.Bounds.Width, subItm.Bounds.Height), NodeStringFormat)

Else

If (e.State And Windows.Forms.ListViewItemStates.Selected) =
Windows.Forms.ListViewItemStates.Selected Then

e.Graphics.DrawString(subItm.Text, subItm.Font, New
Drawing.SolidBrush(Drawing.Color.White), New
Drawing.RectangleF(subItm.Bounds.Left, subItm.Bounds.Top +
((subItm.Bounds.Height - CInt(e.Graphics.MeasureString(subItm.Text,
subItm.Font).Height)) \ 2), subItm.Bounds.Width, subItm.Bounds.Height),
NodeStringFormat)

Else

e.Graphics.DrawString(subItm.Text, subItm.Font,
Drawing.SystemBrushes.HotTrack, New
Drawing.RectangleF(subItm.Bounds.Left,subItm.Bounds.Top +
((subItm.Bounds.Height - CInt(e.Graphics.MeasureString(subItm.Text,
subItm.Font).Height)) \ 2), subItm.Bounds.Width, subItm.Bounds.Height),
NodeStringFormat)

End If

End If

End If

Next

End Sub



it fails miserably! My bounds always seem to come out with a bad numberl ike
this

{X=2000815513,Y=17,Width=16,Height=17}

why?! how do i render sub items in the item draw event properly?
 

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