Drawsubitem event not firing in Ownerdraw Listview Tile mode

cactscool

New member
Joined
Jul 8, 2009
Messages
2
Programming Experience
Beginner
Hello, First i want to apologize for resorting to making a thread about this because i try to exhaust every option before asking for help.

What i'm trying to achieve is I have a listview that is in owner draw, i have several subitems to each tile in this listview but when i changed to owner draw only the index of the item is showing. (the text).

the MSDN site says in tile mode, drawsubitem must be handled in the drawitem event. And gave me some very vague description about how to do this.

i'm an intermediate level VB'er and built many DB driven small scale apps. but sadly am not that familiar with adding event handlers.

would it be possible to provide some code examples here?


this is my code so far, which draws the first item fine, but no subitems appear

VB.NET:
Expand Collapse Copy
    Private Sub lvPlateMap_DrawItem(ByVal sender As Object, _
    ByVal e As DrawListViewItemEventArgs) _
    Handles lvPlateMap.DrawItem


        If Not (e.State And ListViewItemStates.Selected) = 0 Then

            ' Draw the background for a selected item.
            e.Graphics.FillRectangle(Brushes.LightGray, e.Bounds)
            e.DrawFocusRectangle()

        Else

            ' Draw the background for an unselected item.
            Try
                e.Graphics.FillRectangle(Brushes.WhiteSmoke, e.Bounds)
            Finally

            End Try

        End If

        ' Draw the item text for views other than the Details view.
        If Not Me.lvPlateMap.View = View.Details Then
            e.DrawText()
        End If
    End Sub

    Private Sub listView1_DrawSubItem(ByVal sender As Object, _
    ByVal e As DrawListViewSubItemEventArgs) _
    Handles lvPlateMap.DrawSubItem

        Dim flags As TextFormatFlags = TextFormatFlags.Left

        Dim sf As New StringFormat()
        Try

            ' Store the column text alignment, letting it default
            ' to Left if it has not been set to Center or Right.
            Select Case e.Header.TextAlign
                Case HorizontalAlignment.Center
                    sf.Alignment = StringAlignment.Center
                    flags = TextFormatFlags.HorizontalCenter
                Case HorizontalAlignment.Right
                    sf.Alignment = StringAlignment.Far
                    flags = TextFormatFlags.Right
            End Select

            ' Draw the text and background for a subitem with a 
            ' negative value. 
            Dim subItemValue As Double
            If e.ColumnIndex > 0 AndAlso _
                Double.TryParse(e.SubItem.Text, NumberStyles.Currency, _
                NumberFormatInfo.CurrentInfo, subItemValue) AndAlso _
                subItemValue < 0 Then

                ' Unless the item is selected, draw the standard 
                ' background to make it stand out from the gradient.
                If (e.ItemState And ListViewItemStates.Selected) = 0 Then
                    e.DrawBackground()
                End If

                ' Draw the subitem text in red to highlight it. 
                e.Graphics.DrawString(e.SubItem.Text, _
                    Me.lvPlateMap.Font, Brushes.Red, e.Bounds, sf)

                Return

            End If

            ' Draw normal text for a subitem with a nonnegative 
            ' or nonnumerical value.
            e.DrawText(flags)

        Finally
            sf.Dispose()
        End Try

    End Sub
 
this is my code so far, which draws the first item fine, but no subitems appear
You have no code in DrawItem event handler to draw sub items. As help says, DrawSubItem event is not used in Tile view mode.
 
I figured it out in a un-related google search about drawstring

i just use

e.Graphics.DrawString(subItm.Text, drawFont, drawBrush, e.Bounds)
 
Back
Top