You can have more than 32736 items in a combobox - trouble is that you cannot retrieve items via the List property that occupy positions higher than 32736.
However, hitting the API allows us to achieve this. Try something like the following: [tt]
Public Function GetComboItem(cbCombo As ComboBox, lItem As Long) As String
Dim strTemp As String
strTemp = Space(SendMessage(cbCombo.hwnd, CB_GETLBTEXTLEN, lItem, "")
SendMessage cbCombo.hwnd, CB_GETLBTEXT, lItem, strTemp
GetItem = strTemp
End Function
Um - you'll need the following declarations as well. Not sure how I managed to leave them out... [tt]
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Const CB_GETLBTEXT = &H148
Private Const CB_GETLBTEXTLEN = &H149
Just because I am curious. What exactly do you expect your end user to do when confronted with a combobox with over 30,000 items in it? Would it not be better to code some way to restrict the items in the combobox? For example allow them to enter the first 2-3 characters of the item they are looking for and then populate the combo only with items that match.
Yeah, well around here I am not known for my tact. I have just seen so many truly awful user interfaces in my time that I like to pose these questions from time to time.
how/where did you learn how to use the sendmessage API? I look up the parameters for it and it seems to be a general function to be use in many cases. The instructions on how to use it is a bit crytic to me. So i was wondering how you would find out what information goes into each parameter for all the different uses of the function.
Boy, tough question. It's been so long since I started using SendMessage that I can't remember where I picked it up from. But it's a pretty important function. I suspect I picked it up from an early edition of Petzold's book, Programming Windows
A large part of the functionality of Windows relies on messages (the main loop of any window - and the small w is deliberate - basically just waits for a message to arrive in it's message queue, and then takes appropriate action based on the message).
So SendMessage is an important API call, and one that can be a useful and powerful tool in the Windows programmers toolbox.
As you've basically realised, it is a generic function. You basically tell it which window you want to send the message to, which message you want to send, and then two additional paramters, the specific values of which are dependant on the message you are sending.
Now, whilst I know some of those messages, I sure don't profess to know them all. They are, however, documented on MSDN. Trouble is knowing what they are called.
There are a few tricks that can help:
1) A lot of the messages are defined as Constants in the API text viewer. So you can look through that to find apprpriate sounding ones for something you might want to do.
2) Even with the above, you still have the prooblem that there are a lot of COnstants to search through, so its worth knowing that most of the standard controls (listboxes, comboboxes, listviews, etc.) have their own set of messages, which are all identified by two or three characters. General windows messages start WM_, Listboxes start LB_, comboboxes start CB_, edit controls ( VB's textbox) start EM_, ListViews start LVM_, etc. So now you can switch to Constants in the API text Viewer, tap in the identifying letters, and you get scrolled to correct section for a list of available messages. Then you can do a search in MSDN based on whichever message seems to look promising, and that documentation will tell you what wParam and lParam need to be for that particular message.
3) Another way of finding lists of windows messages (and one that can also show what message is doing what) is the SPY++ utility that comes with VB6 Professional (not sure if it comes with Standard)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.