+ Reply to Thread
Results 1 to 3 of 3

Thread: Drawsubitem event not firing in Ownerdraw Listview Tile mode

  1. #1
    cactscool is offline VB.NET Forum Newbie cactscool is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Jul 2009
    Age
    41
    Posts
    2
    Reputation
    0

    Default Drawsubitem event not firing in Ownerdraw Listview Tile mode

    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

    Code:
        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

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Age
    37
    Posts
    11,043
    Reputation
    1563

    Default

    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.

  3. #3
    cactscool is offline VB.NET Forum Newbie cactscool is on a distinguished programming path ahead
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Jul 2009
    Age
    41
    Posts
    2
    Reputation
    0

    Default

    I figured it out in a un-related google search about drawstring

    i just use

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

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts