Solved

combo box first displayed item

Posted on 2004-04-13
4
190 Views
Last Modified: 2010-05-02
Hi all,
I'd like to know how can I set a particular string as the default item into a combo box (VB 6).

I use a combo box with Style property = 2 (i.e. a dropdown list) to display an ORDERED list of string coming from a db field.
During a search process, the user should choose one of them but he could not choose it at all (because it's not a necessary clause in the criteria), so I manually added to the list the word 'ANY'.
Well, since the combo list is ordered ANY does not appear at the first index and the first cell of the combo is always blank.

So, 2 questions:

I need to have an ordered combo where the first voice is always ANY and ANY must be visible as first element also without any selection on the combo.
Is it possible and how ? (I cannot do this through setting Text property since it's read only)

If I need to know the index number of a given element (string), which function returns it ?



Thanks for any kind of help.
Best,
Irene
0
Comment
Question by:new_irene
4 Comments
 
LVL 1

Accepted Solution

by:
prgmrdave earned 20 total points
ID: 10814444
I like to use something like "(Any)", in parentheses, because the parentheses sort ahead of any alphabetic characters.

You can cause it to be selected initially using:

cboSearch.ListIndex = 0

There is no function to tell you the index of a given string; you have to search for it:

For I = 0 To cboSearch.ListCount - 1
    If cboSearch.List(I) = sTerm Then
        bFoundIt = True
        Exit For
    End If
Next I

Hope this helps,

David
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now