Quote:
Originally Posted by ComputersAreFun
I want them to line up.
I tried String to pad it like this: last_name + ''," + string(20-length(last_name)," ") + first_name etc...
But they still don't line up. I suspect the font is at fault.
|
You suspect right!
If this is the path you wish to go down (which, personally, I wouldn't), then you will need to use a monospace font. i.e. Courier.
Courier makes sure that every character takes up the same amount of pixels on your screen. Whether it's a 'W' or a ','. For example, the [ CODE ] tags for these posts use courier, so:
Code:
WWWW
,,,,
This is a sentance with only vowels
i i a e a e i o o e
Gives you the idea.
Personally, I would avoid going down this route, because you'll run into problems if you get a long name for example.
You can't use vbTab in as part of the strings that are listed in the combo box, so that's a no go.
I would:
1) Make a listbox, that's only tall enough for one row, with your 4 columns.
2) I'd then set an 'AfterUpdate()' event for it, to change its height, from one row, to x rows, and vice versa, giving the impression of it being a combobox.
3) I'd then set a 'LostFocus()' event for it, to ensure that it returns to one row, if a user doesn't make a choice, and moves to a different control.
So, so far you have a piece of code that looks like:
Code:
Public switch As Boolean
Public curLng As Long
Option Compare Database
Private Sub tmpList_AfterUpdate()
If (switch) Then
curLng = Me.tmpList.ListIndex
Me.tmpList.Height = 280
switch = False
Else
curLng = Me.tmpList.ListIndex
Me.tmpList.Height = 2000
switch = True
End If
End Sub
Private Sub tmpList_LostFocus()
switch = True
Me.tmpList.Height = 280
Me.tmpList.ListIndex = curLng
End Sub
The ListIndex is used to allow the bottom items of the list (that are effectively 'cut off', when the list is shrunk back to one row) to remain in view when selected.
If you wanted to get more technical about it, there are a couple of things that aren't particularly nice about it. For one, the \/ icon that is usually next to the combobox, obviously won't be there, instead you have an up and down arrow. This you could cover up with a label, that has its background/foreground colour set to match the colour of the form, and then simply toggle its '.visible' element to true or false, depending on whether the listbox has one row or several.
Another thing that isn't particularly convincing (for making it look like a true combobox) is that the selected item, the one that you'll see when you navigate to the next control on your form, will have a black, highlighted, background. This can be overcome by:
1) Storing the selected value(s) in a Public variable/array.
2) Then adding immediately after step 1, 'tmpList.Selected(tmpList.ListIndex) = False', to deselect it.
3) When you need to reference the value that is shown in the combobox, you would then simply reference the Public variable/array instead.
With those two slight modifications, you'd have exactly what you were after, but with a little more work and coding involved.