CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Aug 1999
    Location
    Pakistan
    Posts
    366

    ListView Control and Images

    How do I transfer a selected icon in a ListView control to a Command Button
    e-g
    cmd1.pic=??????

    Thankx in Advance

    PS: same for iMAGE Combo


  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: ListView Control and Images


    well, first the command button's style must be set to 1 - graphical. This is a read only property so you must manually set it in the properties dialog box before you compile the program. when the user clicks on an icon, make sure you know the path to that icon. the code to place that icon on the command button would be similar to this:

    set Command1.Picture = LoadPicture("C:\icons\youricon.ico")




    If you are using VB6 then this should work, VB5 command buttons don't have a picture property or a style property.

    Hope this helps,
    John

    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Join Date
    Aug 1999
    Location
    Pakistan
    Posts
    366

    Re: ListView Control and Images

    This is all very simple but this will not work for a LISTVIEW/IMAGECOMBO Control.
    Thankx in Advance


  4. #4
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: ListView Control and Images

    Then we might a little more clarification...
    1) Do you have the path to the icon in the list view?
    2) Are the icons in a DLL?
    3) Do the icons show up in the list view control? Or do you want them to show up when the user clicks the command button?
    4) Do you have an ImageList control on the form?

    basically, where are the icons located? and where do you want them to go? and where does the command button fit in?

    Because in your original post, this is how i read it:
    You have a listview control showing a group of icons.
    When the user clicks the command button, after they have selected an icon, that icon should show up on the command button as a graphic.
    For the image combo, they select an icon which should then be displayed on the command button.

    if this is not what you are talking about, then please give a more accurate description of what you are trying to do and what you already have.

    Thanks,
    John

    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  5. #5
    Join Date
    Aug 1999
    Location
    Pakistan
    Posts
    366

    Re: ListView Control and Images

    Yes John you figured it right
    I want
    1) the user to select an icon from the ListView
    2)The user should click on the Command Button and the selected item should come onto the Command Button

    Yes I have an Image list and the ListView is bound to it.

    As far as the path of the icon is concerned THAT IS THE PROBLEM. HOw to catch which icon the user has selected in a listview.
    I have tried changing the Caption of the button to the text of the icon in a ListView and it works fine using the ListItems property

    I hope that it is clear now
    Thankx in Advance


  6. #6
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: ListView Control and Images

    Okay, here you go:

    private Sub Command1_Click()
    Dim itm as ListItem
    Dim x as ListImage
    Dim i as Integer

    set itm = ListView1.SelectedItem

    for Each x In ImageList1.ListImages
    If x.Key = itm.Icon then
    ' now we have the index of the icon
    i = x.Index
    Exit for
    End If
    next

    set Command1.Picture = ImageList1.ListImages(i).ExtractIcon

    End Sub



    Be sure to set the style property of the command button to 1 - Graphical, and remember, this only works in VB6.

    Have fun,
    John


    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  7. #7
    Join Date
    Aug 1999
    Location
    Pakistan
    Posts
    366

    Re: ListView Control and Images

    Wow That works.
    thanks anywat .PLease note that you have to use
    (i+1) instead of using i in

    set Command1.Picture = ImageList1.ListImages(i + 1).ExtractIcon



    Thans once again


  8. #8
    Join Date
    Sep 1999
    Posts
    202

    Re: ListView Control and Images

    or
    Me.Command1.Picture = Me.ListView1.Icons.ListImages(Me.ListView1.SelectedItem.Icon).Picture



  9. #9
    Join Date
    Sep 1999
    Posts
    202

    Re: ListView Control and Images

    or:

    private Sub Form_Click()
    Dim iml as ImageList, idx as Integer

    With me.ListView1
    If .View = lvwIcon then
    set iml = .Icons
    idx = .SelectedItem.Icon
    else
    set iml = .SmallIcons
    idx = .SelectedItem.SmallIcon
    ' or for subitem icon
    ' idx = .SelectedItem.ListSubItems(1).ReportIcon
    End If
    End With
    If idx then
    me.Command1.Picture = iml.ListImages(idx).Picture
    else
    me.Command1.Picture = LoadPicture() ' clear button picture
    End If
    End Sub





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

Featured