|
-
February 10th, 2000, 10:48 AM
#1
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
-
February 10th, 2000, 12:23 PM
#2
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
-
February 11th, 2000, 12:43 PM
#3
Re: ListView Control and Images
This is all very simple but this will not work for a LISTVIEW/IMAGECOMBO Control.
Thankx in Advance
-
February 11th, 2000, 01:16 PM
#4
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
-
February 12th, 2000, 08:10 AM
#5
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
-
February 12th, 2000, 04:53 PM
#6
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
-
February 12th, 2000, 11:54 PM
#7
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
-
February 13th, 2000, 06:26 AM
#8
Re: ListView Control and Images
or
Me.Command1.Picture = Me.ListView1.Icons.ListImages(Me.ListView1.SelectedItem.Icon).Picture
-
February 13th, 2000, 06:30 AM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|