Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Components & Controls > Listviews / Treeviews

Listviews / Treeviews Anything related to listview and treeview components

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-08-2009, 6:24 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jul 2009
Age: 41
Posts: 2
Reputation: 0
cactscool is on a distinguished programming path ahead
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-08-2009, 6:44 PM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 37
Posts: 10,173
Reputation: 1273
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

Quote:
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.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-08-2009, 7:49 PM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jul 2009
Age: 41
Posts: 2
Reputation: 0
cactscool is on a distinguished programming path ahead
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 1:06 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.