PDA

View Full Version : List Box Item = ImageName



wpeacock
2005-01-11, 03:16 AM
Using AC2000

I'm new to VB so be gentle...

I want to load a wmf image into an image box when an item is selected from a list box.

I'm using the following code but can't get this to work (not to sure if its the correct event... Is there a leave event to a list box???)

Private Sub ListBox1_Exit()
If ListBox1.Value = "1.2m" Then
imgProtection.imageName = "C:Program FilesACAD20001.2m.wmf"
End Sub


Any Ideas??

Wayne

RobertB
2005-01-11, 03:34 AM
This very brief sample shows how to change the Image control every time you pick an item in the ListBox control. Hopefully it will give you a start.

Private Sub ListBox1_Change()
Select Case ListBox1.Value
Case "ABC"
Me.Image1.Picture = LoadPicture("C:\Temp\1.bmp")
Case "DEF"
Me.Image1.Picture = LoadPicture("C:\Temp\2.bmp")
End Select
End Sub

Private Sub UserForm_Initialize()
Me.ListBox1.AddItem "ABC"
Me.ListBox1.AddItem "DEF"
End Sub

CADfunk MC
2010-05-14, 09:46 PM
Hi everybody / anybody. I am also doing something like this, but I'm using a different approach.

The problem I am bumping into with my approach is that my userform only shows the first preview of the file I would like to see. I don't know why. When I loaded these filenames into a Combobox earlier today the preview updated fine when changed the selection. But when I chane the selection in the listbox, the first drawing I selected remains the only preview I see. Does anybody know why? Here is the code that might contain the culprit:



If LboxOne.ListIndex = -1 Then Exit Sub
For i = LboxOne.ListCount - 1 To 0 Step -1
If LboxOne.Selected(i) = True Then
DrawingFileName = (LboxOne.List(MySelSet))
Filename = StrPath & DrawingFileName
End If
Me.DwgThumbnail1.DwgFileName = Filename
Next i


Off course any help will be greatly appreciated!

Coolmo
2010-05-15, 11:11 PM
where is the "MySelSet" variable set? It looks like a listbox index location and carrying over from something? This is what you're telling the thumbnail to show but it never changes (according to your code)

CADfunk MC
2010-05-16, 02:09 AM
Thanks for the reply. It's dimmmed as an integer earlier in the "LBoxOne_Click" procedure, and set to 0 after the dims. I did this supposing that every time I click on the listbox a new selection would be made, and the macro would run again. It seems I am wrong?

I 've searched the web for quite a while trying to figure out why its not working. One thing I found interesting (though that didn't solve it either) was the option of lining a change in the selection to the mousedown click:

Private Sub LBoxOne_MouseDown(ByVal Button _
As Integer, ByVal Shift As Integer, ByVal X As Single, _
ByVal Y As Single)
LboxOne.ListIndex = -1
End Sub

This is a VB macro that seems to be made for noticing a change in selction too, but it doesn't work in VBA :


'Private Sub LBoxOne_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
'End Sub

It seems the solution could be obvious, but I'm quite stuck. Thank you for thinking along with me.

CADfunk MC
2010-05-16, 04:16 AM
Finally I got it. I used msgbox and found something was buggy about the code itself (as you suggested), so I rewrote it.

MySelSet = 0

Do While MySelSet < LboxOne.ListCount
If LboxOne.Selected(MySelSet) Then
' files need to be saved as AutoCAD 2004: higher is invalid format
DwgThumbnail1.DwgFileName = "G:\Symbols\" & (LboxOne.List(MySelSet))
End If
MySelSet = MySelSet + 1
Loop

Then I saved my files in a 2004 format (I suppose they weren't recognised by dwgthumbnail). For now this seems to work ok for my purposes.

Coolmo
2010-05-17, 12:06 AM
I was going to suggest replacing the "MySelSet" variable with the "i" (list index that was selected) in your original code. "MySelSet" was always set to 0 and was never changed to the index of the selected list item once "LboxOne.Selected(i)" was found to be true. Either that or put a line in there that sets "MySelSet" to i and then call the drawing thumbnail filename.

CADfunk MC
2010-05-17, 07:26 PM
I tried what you said and that works well too. Thanks for the help!