chem1
February 10th, 2000, 09:48 AM
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
e-g
cmd1.pic=??????
Thankx in Advance
PS: same for iMAGE Combo
|
Click to See Complete Forum and Search --> : ListView Control and Images chem1 February 10th, 2000, 09:48 AM 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 Johnny101 February 10th, 2000, 11:23 AM 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 chem1 February 11th, 2000, 11:43 AM This is all very simple but this will not work for a LISTVIEW/IMAGECOMBO Control. Thankx in Advance Johnny101 February 11th, 2000, 12:16 PM 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 chem1 February 12th, 2000, 07:10 AM 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 Johnny101 February 12th, 2000, 03:53 PM 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 chem1 February 12th, 2000, 10:54 PM 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 Bruno February 13th, 2000, 05:26 AM or Me.Command1.Picture = Me.ListView1.Icons.ListImages(Me.ListView1.SelectedItem.Icon).Picture Bruno February 13th, 2000, 05:30 AM 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 codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |