Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need multiple columns in ComboBox (VB6)

    I am trying to work best I can with the limitation of the ComboBox in VB6. I need to display two categories of data in the drop down and have been trying to write a routine to format everything so it places spaces to try and make the second "column" line up. My problem is it never seems to be consistent. Simply using the Spaces() method and subtracting the length of the length of the string of the second column isn't working. This is due, I think, to the font pitch being different on every line item.

    I know I can't be the first one who has needed multiple column capability and was wondering if anyone else has a trick to make the display do a reasonable job of emulating multiple columns?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Need multiple columns in ComboBox (VB6)

    Can you change to a fixed pitch font such as Courier New? Otherwise, the math probably would get pretty intense.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need multiple columns in ComboBox (VB6)

    Can you give me some other choices of fixed fonts? I like the idea, just don't like Courier New

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Need multiple columns in ComboBox (VB6)

    Problem is that you can be sure that Courier New is available on every PC - it's part of every Windows installation, but you can't be sure about other fixed-width fonts. (If this is just fro your own use, you decide which font to use)

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Need multiple columns in ComboBox (VB6)

    MS San Serif is fixed. Try that.
    Charlotte

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: Need multiple columns in ComboBox (VB6)

    <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

  7. #7
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need multiple columns in ComboBox (VB6)

    Well, the application is running off of a Citrix environment so everyone should have the same fonts available. I'm starting to think that I'm going to have to resort to math. Problem is I've already tried that but depending on which order the records are displayed in the drop down, the math doesn't seem to be applied consistently.

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Need multiple columns in ComboBox (VB6)

    Okay, it took a REALLY long time to find this, but here's your entry point into the math. There's an API call named GetTextExtentPoint32 that returns the length of a string using the character widths stored in the font files.

    <pre>Private Type SIZE
    cx As Long
    cy As Long
    End Type

    Private Declare Function GetTextExtentPoint32 Lib "gdi32" _
    Alias "GetTextExtentPoint32A" _
    (ByVal hDC As Long, _
    ByVal lpSz As String, _
    ByVal cbString As Long, _
    lpSize As SIZE) As Long</pre>


    Some useful pages:

    Windows GDI: GetTextExtentPoint32 (uses C syntax)
    Setting a Command Button's ForeColor (source for above declarations)
    ActiveX and Visual Basic: Enhance the Display of Long Text Strings in a Combobox or Listbox (esp. Figure 3, showing partial VB syntax)

    Hope this helps, though I can't say I fully understand it. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

  9. #9
    2 Star Lounger
    Join Date
    Nov 2001
    Location
    London, UK, England
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need multiple columns in ComboBox (VB6)

    I've found it best to use a 3rd party control for multiple columns in combo boxes. There are a selection of controls from BeCubed software that are solid, alternatively you can check out the full source from vbAccelerator for Steve's owner drawn combo box - I think it has multi-columns.

    http://www.vbaccelerator.com/home/VB/Code/...Full_Source.asp

    I still can't believe this was overlooked in the VB6 combo box, it's so easy to do in MSForms controls - how hard would it have been for Microsoft to duplicate this??!!

  10. #10
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need multiple columns in ComboBox (VB6)

    Wow, you did do some digging - thanks. Quite honestly, I think it is a bit beyond me, though it does seem to show promise.

  11. #11
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need multiple columns in ComboBox (VB6)

    Thanks, I will check them out. Unfortunately, I am using the Infragistic menu bar control's combo box so I don't really have a choice of using a different after-market control. And I agree, and am sure we aren't the only ones frustrated with Microsoft's lack of functionality of this control compared to their lesser products. I've done some basic math in trying to make the columns line up and I've got it real close, but still doesn't look very professional.

  12. #12
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Need multiple columns in ComboBox (VB6)

    <P ID="edit" class=small>(Edited by jscher2000 on 27-Jun-03 12:21. Had a bit more fun with the example...)</P>I'm probably confused because I work in VBA with MSForms, and not in VB6 with whatever its controls are, but I just wanted to confirm that the built in, multiple-column functionality of the ComboBox isn't satisfactory for your needs.

  13. #13
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Need multiple columns in ComboBox (VB6)

    Mike,

    Comboboxes on menubars are usually quite different from the built-in controls you would put on a form, and you are, in fact, using an aftermarket control if it comes with the Infragistic control. That behavior is determined by the publisher and what they expose, not by Microsoft.
    Charlotte

  14. #14
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Jeddah, Saudi Arabia
    Posts
    243
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need multiple columns in ComboBox (VB6)

    I use Tab. Seperate the strings with vbTab instead of Spaces(n).

    myString=Sring1 & vbTab & String2 etc.

    I know this doesn't give me control over how far the 'columns' are apart but for simple lists it's sufficient for what i want to do.

    Regards,

    Kevin Bell

  15. #15
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Need multiple columns in ComboBox (VB6)

    Correct, actually, the functionality is slightly different between VBA and VB. In VBA/Access the ComboBox exposes features such as multiple columns addressable through an arrayed index, column headers, I think even a grid as part of the drop down. In VB, for some reason, they didn't carry this over and don't expose any of the features of its VBA counterparts. Your UserForm1 example would be ideal if I could get it to do that with a non fixed width font. Put a highlighted column header on it and it would be perfect.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •