Results 1 to 14 of 14

Thread: ListView1.SelectedItem.SmallImage = ???

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Question ListView1.SelectedItem.SmallImage = ???

    I have the following:
    VB Code:
    1. Private Sub cmdLargeFish_Click()
    2. Dim lvwItem   As ListItem  
    3.    Set lvwItem = ListView1.SelectedItem
    4.    If Not lvwItem Is Nothing Then
    5.       lvwItem.SmallImage = "LARGE_FISH"
    6.       Set lvwItem = Nothing
    7.    End If
    8. End Sub
    9.  
    10. Private Sub cmdIllFish_Click()
    11. Dim lvwItem   As ListItem  
    12.    Set lvwItem = ListView1.SelectedItem
    13.    If Not lvwItem Is Nothing Then
    14.       lvwItem.SmallImage = vbNullString/0 'What the heck do you put here to REMOVE/CLEAR the image??? :(
    15.       Set lvwItem = Nothing
    16.    End If
    17. End Sub
    How can I remove the image from the selected item???

    Woka

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Try 0?

  3. #3
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    SmallImage = SmallIcon

    And try Null?
    Don't Rate my posts.

  4. #4

  5. #5
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Originally posted by Pc_Madness
    SmallImage = SmallIcon

    And try Null?
    Am I off the track?
    Don't Rate my posts.

  6. #6

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Yea, small Icon D'Oh

    Err...setting it to 0 does the trick, this removes the icon, BUT the listview doesn't repaint it'self
    If you drag a random application of the window, then move it, the icon disappears when the listview repaints...How can I force this...without subclassing...
    Actually I could just sent the REPAINT message to the listview...Hmmm, that's an idea...

    Off to check...

    Woka

  7. #7
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Other than that....the API SetWindowPos will repaint the screen
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  8. #8
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Or...
    VB Code:
    1. Const RDW_INVALIDATE = &H1
    2.  
    3. Declare Function RedrawWindow Lib "user32" Alias "RedrawWindow" (ByVal hwnd As Long, lprcUpdate As RECT, ByVal hrgnUpdate As Long, ByVal fuRedraw As Long) As Long
    4.  
    5. ' And to repaint...
    6. RedrawWindow [i]Object[/i].hwnd, ByVal 0&, ByVal 0&, RDW_INVALIDATE

  9. #9
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    smartarse Ax
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  10. #10
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    Originally posted by Blobby
    smartarse Ax
    One tries one's best

  11. #11

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Why not send the correct windows message for the listview though?
    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    2.  
    3. Private Const LVM_FIRST = &H1000
    4. Private Const LVM_REDRAWITEMS = (LVM_FIRST + 21)
    5.  
    6. 'Some function
    7. SendMessage lvwData.hwnd, LVM_REDRAWITEMS, ByVal 0&, ByVal 0&
    Does the trick perfectly by redrawing the listitems

    Cheers for the help people...

    Woka

  12. #12
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Unhappy More help please

    Hello Woka
    I have the same problem as you.
    I also want to remove the smallIcon from my listview.

    When I found your code I jumped high with joy, but landed hard

    with this code, it only redraws the first item in the listview, on the other items the smallicon doesnt dissapear.

    Form with listview and imagelist.
    VB Code:
    1. Option Explicit
    2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    3.  
    4. Private Const LVM_FIRST = &H1000
    5. Private Const LVM_REDRAWITEMS = (LVM_FIRST + 21)
    6.  
    7. Private Sub Form_Load()
    8.    ' Create an object variable for the ColumnHeader object.
    9.    Dim clmX As ColumnHeader
    10.    Dim intx As Integer
    11.    ' Add ColumnHeaders.
    12.    Set clmX = ListView1.ColumnHeaders.Add(, , "test")
    13.     ListView1.BorderStyle = ccFixedSingle ' Set BorderStyle property.
    14.    ListView1.View = lvwReport ' Set View property to Report.
    15.    
    16.    ListView1.SmallIcons = ImageList1
    17.  
    18.    ' Create a variable to add ListItem objects.
    19.    Dim itmX As ListItem
    20.  
    21.    For intx = 0 To 10
    22.       Set itmX = ListView1.ListItems.Add(, , CStr(intx))
    23.       itmX.SmallIcon = 1   ' Set an icon from ImageList.
    24.    Next intx
    25. End Sub
    26.  
    27.  
    28.  
    29. Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
    30.     If Item.SmallIcon <> "on" Then
    31.         Item.SmallIcon = "on"
    32.     Else
    33. 'Remove the smallicon
    34.         Item.SmallIcon = Empty
    35. '        Item.SmallIcon = "off"
    36.     End If
    37. 'repaint the listview
    38. SendMessage ListView1.hwnd, LVM_REDRAWITEMS, ByVal 0&, ByVal 0&
    39.  
    40. End Sub

    I cant find the const that will repaint the whole listview. Do you have any idea?
    Onerrorgoto

    Dont be to optimistic, the light at the end of the tunnel might be a train

  13. #13

  14. #14
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Unhappy Hmm, why doesnt my code work?

    Hello Woka
    Thanks for the fast reply.

    It funny that my code doesnt work (actually not ) when yours do.

    In my code in the previous post, only the first item in the listview toggles the smallicon when I click on it. the other 9 items doesnt change at all

    In the imagelist I have two images, with key= "on" & "off". It works fine to toggle between the two images but when I want to toggel between "on" and no icon, only the first item works.

    Any ideas?
    Onerrorgoto

    Dont be to optimistic, the light at the end of the tunnel might be a train

Posting Permissions

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



Click Here to Expand Forum to Full Width