Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a half-way decent dropdown control in VB?

Status
Not open for further replies.

icodian

IS-IT--Management
Aug 28, 2001
74
US
I'm no expert in this by any means so forgive me if this is a dumb question.

I created a small database in Access. I then created a form to go with it that allows the user to select an Order Number. The Order Number is simply pulled from one of the tables available.

To do this, I added a combo box and entered the fields I wanted it to display into the properties. SO #, Date, Cust #, Cust Name. When I select the dropdown box on the form, I can see all of the fields clearly and each one appears in its own column. Additionally, the column headers are included. I can make the combo box 3 characters wide, but when I select to drop it down, I can still see all 4 columns. In other words, the dropdown portion of the box expands to accomodate the info.

I have been struggling do create the exact same form in VB. I cannot find a simple combo box that will allow me to perform the same simple format. Is there one out there? The only thing I have been able to do is get the 4 fields into the dropdown. The formatting is terrible and in order to see all of the info when I drop the box down, I have to make the width of the dropdown box go across half of the screen. i.e. I have a very wide and narrow form which is kinda silly.

To sum it all up, here is what I am hoping for:
1. Dropdown box itself is small. When pressing the dropdown arrow, the lower "dropdown" portion will expand to display all selected data.
2. Include all 4 columns in the dropdown. Each column should be left aligned and I'd like a delimter between them such as | (pipe).
3. Column headers should be displayed for each column.

Is there a nice combo box control somewhere that will allow me to do this through VB? The only ones I've found:
1. Must be extremely wide to accomodate all of the information from the 4 fields.
2. Must concatenate all of the fields in order to display them all. Only allows you to List one field by default.
3. Does not display column headers.

Any help would be appreciated.
 
There is none built into VB, I am not sure about .NET yet, I haven't used it yet. I had to make my own combo box control to do this. Days worth of work and it still isn't 100% but it looks and works good enough to put in my projects... There are a few out there that are free, but you still have to fix most of them or be a good programmer to figure out what is going on... I hope this helps a little...

Aaron
 
When using the contron in vb are you setting the column count property properly?
The combo box control in vb has been working fine for me. (not great, but fine).
 
I have used a Combo Box/List Box combination in the past. It is not a pretty solution, but it works.

Firstly, create a dropdown list box with the width for containing the required values (ie. order number).

Now, populate the dropdown list box with the order numbers only.

Secondly, create a list box (that possibly holds 5 lines). Make sure the font used is a fix-width font such as Courier New.

Now, populate the list box with everything you need. However, to "simulate" columns, pad out each field.

So, if an item contains Order Number, Order Description, and Order Cost, then each field out with spaces so every item will be of the same length (and everything will line up).

For example, Order Number might have a maximum length of 10 characters, so, you pad the order number out to 12 characters:

Code:
For i= (len(order_number) + 1) to 12
   order_number = order_number + " "
next i

Do the same for the other fields.

Then add the item to the drop down list:

Code:
strItem = order_number + order_descrip + order_cost
list1.addItem strItem

Next, set the list box to hidden.

Make sure that the list box is flush up against the dropdown list box's bottom edge.

Next, write a small bit of code for the dropdown event:

Code:
Private Sub Combo1_DropDown()

    List1.Visible = True
    List1.SetFocus

End Sub

The SetFocus ensures the dropdownlist in fact doesn't remain dropped down.

Next, write the code:

Code:
Private Sub List1_Click()

   Combo1.Text = Combo1.List(List1.ListIndex)
   List1.Visible = False

End Sub

And there you have it. Just make sure the Combo1 and List1 controls are populated in the same order and you have a "simulated" multi-column drop down box. As I said, it isn't pretty, but provides a quick 'n' nasty work around for the annoying absence of one.

Cheers,

OzWolf
 
Follow-up, if you want a quick demo app, just tell me and I will e-mail one through.
 
As an alternative (a somehow more stetic and definitely faster one) create your form in your Access mdb file and open the form from VB.

This worked better for me when in a hurry. Not the most elegant piece of code though.
 
...er..

I take it back from my firs posting on this thread....

"When using the control in vb are you setting the column count property properly?"

This obviously applies to combobox in Access vba.

You may want to take a look at DataCombo (in VB) contained in \\windows\system\msdatlst.ocx.

Check documentation in MS site, look under "DATACOMBO CONTROL"

Regards
 

Another option is:

Do a search in this forum under the keyword:

microsoft forms

Exact phrase, any date [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanks for the suggestions and options guys. I will look into these.

Ozwolf, I really appreciate the offer of the demo app. I will look into some of these other ideas and definitely let you know if I can't work them out satisfactorily.

Thanks again everyone.
 
And yet another option would be to use a hook on a combobox in conjunction with a list box. When the combo is clicked to drop down, the event is cancelled and a list box shows in it's place.

Interested? [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
...or you can simply set a reference to the Access library in your project and use the exact same combo Access uses in VB.

I'm not sure how the licensing would work on distribution for that one though...
 
>I'm not sure how the licensing would work on distribution for that one though...

Non-distibutable with-out the Office Developers kit. A client must already have an owned licensed version of the library installed.
[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
These solutions are all cunning workarounds rather than the real thing though aren't they. I used the Access combo on one job as the customer had access anyway, but it didn't seem to work as well in vb as it does in access. Not sure why.
I spent a long time recently looking for a decent combo with no success. I needed a multi-column auto-completing thing. I also wanted a combo that showed fonts realistically like in Word. I just wanted it to show the fonts I wanted it to show and not all the fonts on my computer. I also didn't want a vb activex stuffed full of timers and reams of dodgy code.
I couldn't find anything at all.
 
petermeachem:

Did you try the combo box from MS Forms 2.0?

Or a combination of a combo and a list box/list view using a hook? Here, you get the benifits of a combo box and a list box/view.

[/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 

>forms 2 has the iffy distribution

Iffy distribution?
What happens if you write a program that needs IE, or paint, or word/note pad, etc, and these are not installed on the client? Just as iffy, if the user hasn't installed them.

Com95 is just as iffy. If the user doesn't have it, they gotta get it, or install it from your distribution media (only here there is no re-distribution problems - but still, if has to be done)

The way I see it it is the same with the MS Forms 2.0.

>Fm20.dll is included with the OSR2 and OSR2.5 releases of Windows 95


>'real' component than a pile of complicated vb that I have to debug.

Then create a 'real' component, user control, yourself.

What's the difference, except a little bit of time and saving on buying one?

The 3rd party controls are not always better, and are often made using the same basic tools in VB which are available to you, and if they ARE alot better, then you're going to pay some for it, or spend alot of time creating one yourself.

But you can create a better control yourself using VB with-in a short time.

Once created and tested, you can put it to bed once and for all.
Better than settling for an unprofessional or limited method, or constantly beating around the bush with the available controls in VB. [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top