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
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 ..
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
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 ..
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.
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
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 ..
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"
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"
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.
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 ..
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?
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
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.
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.
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
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
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
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