Page 1 of 2 12 LastLast
Results 1 to 40 of 61

Thread: [RESOLVED] images in listview

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Resolved [RESOLVED] images in listview

    How to get image with Listview items .. the listview with three columns on a form

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: images in listview

    You need to use the imagelist control, add your images to that and then assign an image to the listitem from the imagelist

  3. #3
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: images in listview

    create a listview
    then add a icon from the toolbox called ImageList
    put it in the form where the listview is
    right click on the imagelist there you have insert picture
    now after you finished adding icons
    right click on the listview properties there is a tab called ImageLists
    there you will see and pick how you want it to display in the listview.
    if you leave it empty and try to load the listview then you get a error "imagelist must be initialized before use"
    hope this explains what you need
    good luck

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    Thanks need a sample please

  5. #5
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: images in listview

    here
    Attachment 106051

    dont forget to mark resolved if its resolved

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    Sir Thanks , I want this way .. not on form load event
    Last edited by janu; Oct 19th, 2013 at 12:19 PM.

  7. #7
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: images in listview

    what do you mean this way?
    how do you want to load does values?

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    listbox click event to listview .. each listbox item will have different images as well as items in listview with three column headers .. and there is one more listbox after click event of listview items ..
    Last edited by janu; Oct 18th, 2013 at 03:37 AM.

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    need help please

  10. #10
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: images in listview

    upload your project here

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    without knowing about listview I have not yet started my project ...

    I plan to have a 2 Listboxes and a Listview on a form .. where I have List1 filled with few items which when an item in list1 is clicked there come the result in Listview which should three column header as well as images or icons with each items then when I click on listview items the Listbox2 should have result what so ever .. hope I will be help

    Listbox1 ---> Listview ----> Listbox2

  12. #12
    gibra
    Guest

    Re: images in listview

    Quote Originally Posted by janu View Post
    listbox click event to listview .. each listbox item will have different images as well as items in listview with three column headers .. and there is one more listbox after click event of listview items ..
    ListBox can't shows images.

  13. #13
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: images in listview

    Try writing some code, it is not that hard. You need to add an imagelist to the project, then you need to populate it with images. You use the index of the image in the imagelist to assign it to an item in the treeview.

    Try are plenty of samples around for adding items to a listview no need to write another one.

  14. #14
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: images in listview

    janu a friend sent me the example
    try to play with the code
    Attachment 106099

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    dear salsa31 I have already download it from planet source with the name custom listbox ..
    Ok the example which you gave me before this .. How can I achieve items click events in listview

    Code:
    Private Sub Form_Load()
    
     Dim colX As ColumnHeader
        Dim intX As Integer
       
        
        ListView1.ListItems.Add , , "apple", , 3
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "good"
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "best fruit"
    
        ListView1.ListItems.Add , , "Orange", , 1
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "peel"
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "Best fruit"
    End Sub

    Like when I click on apple .. for result I have listbox ..
    Thanks in advance

  16. #16
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    5,204

    Re: images in listview

    your posts are very confusing
    what are you using?
    listview or listbox?

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    I use both .. I have placed Listbox1 then Listview and then Listbox 2 on form .. what I want when I click on Listbox1 item the listview should display some items and when I click on Listview item [any] Listbox 2 should display its items whatever ..

  18. #18
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: images in listview

    How are the main items in the Listbox linked to the sub items in the Listview.
    Do you have an underlying datamodel or data structure?
    Based on this datamodel it's maybe easier to give an advice then on the requirement "when I click the ListBox the ListView should be updated"

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    the structure is as

    Listbox1

    Code:
    with List1
    .AddItem"fruit1"
    .AddItem"fruit2"
    .AddItem"fruit3"
    
    End With
    Listview with sub items

    Code:
    Dim colX As ColumnHeader
        Dim intX As Integer
       
        
        ListView1.ListItems.Add , , "apple", , 3
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "best"
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "20kg"
    
        ListView1.ListItems.Add , , "Orange", , 1
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "Best"
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "10kg"
    
     ListView1.ListItems.Add , , "Banana", , 1
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "Best"
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "5kg"
    Listbox2

    Code:
     
    with List2
    .AddItem " Sold Out"
    .AddItem"In stock"
    .AddItem"Not Available"
    End With
    on form load event Listbox1 will show its items .. when I click on listbox1 item "fruit1" Listview should display "aaple" with sub items and when I click apple in Listview Listbox2 should display Ist item "Sold Out"

    Hope I get help

  20. #20
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: images in listview

    What should happen if you click on another item in ListBox 1?
    And why should a click on the ListView show "Sold out" in Listbox 2???
    What is the logic behind all this?

    Sorry, my mindreading skills are very bad developed and I lost my crystal ball, so I think I can not help you further.

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    Dear Arnoutdv that was expected .. no problem ... as you said what will happen when I click on next item on listbox1 .. what should be there in listview and when I click on listview what should be there in listbox2 ...logically the master here might understand what I mean to ..




    Last edited by janu; Oct 19th, 2013 at 09:14 AM.

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    I have attached the images in post #21

  23. #23
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: images in listview

    I'll try again.
    Where does the data come from.
    How should the program know what is represented with fruit1,fruit2,fruit3 and whether it is In Stock or Sold Out?

  24. #24

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    Either you are frustrated or you are making me frustrate .. I just need to know about click events in all the three .. I am not using any database .. Just need to know if I click Listbox1 item how can I call Listview to display items similarly If I click Listview item how can call Listbox2 to show its items

  25. #25
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: images in listview

    In the Click event of the ListBox you get the actual item being clicked by checking the .ListIndex property and the .Item property.
    For the ListView control there is the ItemClick event.

  26. #26
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: images in listview

    The concept of the project does not make any sense to me at all.

    Why use a list view to display a single item info?
    Why use a second list to display only the stock status?

    I would say that it would be much better to either

    1: Use a single list box and then use labels, textboxes and or image controls to display all the info of selected item

    or

    2: Use just a single listview and display all the info for all the items in the listview.

    Not only would it be inefficient to use to listboxes and a listview for this but it would be very cumbersome for the user having to click list1 and then listview just to see the stock status of each item.

  27. #27

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    Here I have tried to achieve what I want but I got really stuck on Listview Click event

    Code:
    Private Sub Form_Load()
    With List1
    .AddItem "fruit1"
    .AddItem "fruit2"
    .AddItem "fruit3"
    End With
    End Sub
    
    Private Sub List1_Click()
    Dim colX As ColumnHeader
    Dim intX As Integer
    ListView1.ListItems.Clear
    With ListView1
            Select Case List1.Text
                Case "fruit1"
     ListView1.ListItems.Add , , "apple", , 1
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "good"
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "1kg"
         ListView1.ListItems.Add , , "apple1", , 1
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "best"
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "7kg"
             Case "fruit2"
     ListView1.ListItems.Add , , "Orange", , 1
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "best"
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "10kg"
            Case "fruit3"
     ListView1.ListItems.Add , , "Banana", , 1
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "better"
        ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , "5kg"
            End Select
        End With
    End Sub
    
    Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
    List2.Clear
    With List2
    
            Select Case ListView1.Item
                Case "apple"
                            .AddItem "Soldout"
              Case "apple1"
                            .AddItem "available"
                Case "Orange"
                            .AddItem "In stock"
                Case "Banana"
                            .AddItem "not availabe"
    
    
            End Select
        End With
    
    End Sub
    

  28. #28
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: images in listview

    The clicked object passed in the ItemClick event is "Item", so use Item instead of ListView.Item
    Read the help for the ItemClick event.

  29. #29

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    Please Vb masters need help how to fire click event in Listview ...

  30. #30
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: images in listview

    I just told you.
    You have to correct event only instead of using ListView.Item you should use Item as passed in the event parameters.

  31. #31
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: images in listview

    @janu,

    Why can't you modify the example salsa31 posted to suit your needs?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  32. #32

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    That example is only modified for Listview but how to get click event of Listview like listbox .. That for I am wondering

    here is a sample attached
    Attached Files Attached Files
    Last edited by janu; Oct 19th, 2013 at 10:02 PM.

  33. #33
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: images in listview

    Quote Originally Posted by janu View Post
    Please Vb masters need help how to fire click event in Listview ...
    You were told already your issue is here
    Code:
    Select Case ListView1.Item
    Should be
    Code:
    Select Case Item
    Which would be the item the user actually clicked on

  34. #34

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    Thanks DataMiser and Arnoutdv , it really works .. Now I am trying to insert Listview Items with command button .. I tried but not succeed .. help me here also

    Code:
    Private Sub cmd_Click()
    
    
        ListView1.ListItems.Add , , "sometext", , 1
           
    End Sub

  35. #35

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    need help please

  36. #36
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: images in listview

    What happens if you set a breakpoint on the given line and press the command button?
    Is your button actually named cmd?

  37. #37

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    can you guide by code please

  38. #38
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: images in listview

    Is the above command executed, does it give an error message?
    If not, what is added to the ListView?

  39. #39

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2009
    Location
    vbforums
    Posts
    809

    Re: images in listview

    Quote Originally Posted by Arnoutdv View Post
    Is the above command executed, does it give an error message?
    If not, what is added to the ListView?

    as I have set the gridlines to true and also have set the imagelist in listview property ...when I execute or click on commond button the gridlines gets broad and no item comes .. Listview remains blank

  40. #40
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    5,872

    Re: images in listview

    Remove the last ,1 and see what happens

Page 1 of 2 12 LastLast

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