Image Combo

nathansav

Registered User.
Local time
Today, 06:28
Joined
Jul 28, 2010
Messages
114
Hi,

I have an image combo on my form that is working fine, however, i want the selection to have the primary key of the selection in column (0) but not to be visible, and (1) to have the company name. Can anyone advise, i have tried my conventional method, but it wont allow

i am adding as

imgCboBrokers.ComboItems.Add Index:=cboIndex, Text:=.Fields("Broker_Name").Value, Image:=strImageName

where cboIndex increments by 1 as the recordset moves next.

essentially i want to see

Image, ID, Name

TIA

Nathan.
 
Where have you got the image combo from? I presume it is not native to Access is it?
 
Hi,

No it was an activex control.
 
What's the name of this ActiveX control?

What version of Acces are you using?
 
Microsoft Image Combo Box Control 6.0 SP4

MSComctlLib.ImageComboCtl.2
ImageComboCtl

I am using access 2007 and 2003.

Thanks.
 
I'm sorry, do you want to see the ID or not?
... i want the selection to have the primary key of the selection in column (0) but not to be visible ...

... essentially i want to see
Image, ID, Name ...
If you don't want to see the ID, but you want to be able to retrieve it from the ComboItem object you can set it's Tag property.
Code:
   Dim ci As MSComctlLib.ComboItem
   Set ci = m_cbo.ComboItems.Add(, , "Your Company Name Here", img)
   ci.Tag = "<company ID here>"
And handle the change event ...
Code:
Private Sub m_cbo_Change()
   MsgBox "Selected CompanyID is: " & m_cbo.SelectedItem.Tag
End Sub
But the control doesn't support the concept of columns like a combobox in Access. If you want to see the ID you'd have to fake it in the Text property by adding the ID AND the company name.
HTH
 
Hi,

I did want it to behave the same as a multi-column combo in Access, where the ID would have been column width of 0.

I will try the tag method.

Thanks

Nathan,
 
Hi,

I have tried the tag option and that works fine, thanks a lot for that.

however, i cant get the change event to work, it works when i first load the form and populate the box, but then when i select something, it doesnt start my code.

Private Sub imgCbo1_Change()
MsgBox imgCbo1.SelectedItem.Tag
End Sub

Is there anything wrong with that?
 
In order for this code to run ...
Code:
Private Sub imgCbo1_Change()
  MsgBox imgCbo1.SelectedItem.Tag
End Sub
... you'll need a WithEvents variable called imgCbo1 and it needs to point to a valid instance of an MsComctlLib.ImageCombo, so you need something like this ...
Code:
Option Compare Database
Option Explicit

[COLOR="Green"]'you need a WithEvents variable of the specified type[/COLOR]
private withevents imgCbo1 as MsComctlLib.ImageCombo

private sub form_open(cancel as integer)
[COLOR="Green"]  'you need to point the variable at a valid instance of the object[/COLOR]
  set imgCbo1 = me.ImageCombo1.Object
end sub
Once that's done you can handle events for imgCbo1.
A sort of shorthand way to do this same thing is: above the code window there is a combo that displays '(General)' and lists the objects in the current module. In that combo, find the name of the object whose events you want to handle and click that item. Directly to the right is a second combo that normally shows '(Declarations)' but that now displays a list of the events raised by the object you just selected on the left. Select the event you want to handle, and the IDE inserts the signature for that event automagically.
If you do this, you can handle events directly from the object in the control (ImageCombo1.Object) without declaring a WithEvents variable.
 
Hi,

That was the way i was doing it originally, selecting from the dropdowns at the top.

I will try again the other way.

Keep you posted
 
An advantage of declaring your own variable of the specified type is that you get to use intellisense when you use that variable. To me also the code is more self-explanatory or self-documenting.
Drawbacks are that it's more typing, and your variable will be set to 'nothing' if an unhandled error occurs.
Choices,
 
Hi,

I still cant get the contents of the combo to show.

Can you advise?
 
Sorry, that's not enough failure info. Can you post code? Post a DB? If you post code, also please indicate where it fails if it's a compile or runtime error, and describe the failure if you get a wrong or unexpected result.
Thanks, and cheers,
 
Hi,

Apologies, the code i am using is as follows

<CODE>

Option Explicit
Private WithEvents imgCbo1 As MSComctlLib.ImageCombo
Public blnLoad As Boolean

Private Sub Form_Load()
blnLoad = True
End Sub
Private Sub Form_Open(Cancel As Integer)
Dim imgList As New ImageList
Dim ci As MSComctlLib.ComboItem
Set imgCbo1 = Me.imgCbo1.Object
imgList.ListImages.Add 1, "One", LoadPicture(CurrentProject.Path & "\Export_Excel.jpg")
imgList.ListImages.Add 2, "Two", LoadPicture(CurrentProject.Path & "\CRM_Complete.jpg")
Set imgCbo1.ImageList = imgList
Set ci = imgCbo1.ComboItems.Add(Text:="Option 1", Image:="One")
ci.Tag = 1
Set ci = imgCbo1.ComboItems.Add(Text:="Option 2", Image:="Two")
ci.Tag = 2
blnLoad = False
End Sub
Private Sub imgCbo1_Change()
If blnLoad = False Then
MsgBox imgCbo1.Tag
End If
End Sub

</CODE>
 
In this routine you'll get an error because an ImageCombo doesn't have a .Tag property ...
Code:
Private Sub imgCbo1_Change()
   If blnLoad = False Then
      [COLOR="DarkRed"]MsgBox imgCBO1.Tag[/COLOR]
   End If
End Sub
Other than that, I would add the MS Image List control to the form in design view. The ImageList is a control but it has no visual representation when the form is running. I commonly put it on the form's header so it's out of the way, and I load it with the images I need at design time so the actual image files are no longer needed. You can also set the ImageList property of the ImageCombo at design time.
Cheers,
 

Users who are viewing this thread

Back
Top Bottom