Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to all

First of all sorry for my English

I want to fill a combobox from an access table with code and description but
the code is 10 digits and the Description is 50

I want the description start after the total digits of the code plus 1

Looks like

1          Descr1
12         Descr12
123        Descr123
1234       Descr1234
12345      Descr12345
123456     Descr123456
1234567    Descr1234567
12345678   Descr12345678
123456789  Descr123456789
1234567890 Descr1234567890

Is this possible??
I knew how to fill a combo from access but i don’t knew how to make the description start from the position 11
Thanks and regards.
Posted
Updated 15-Apr-11 3:25am
v2
Comments
Chris Maunder 15-Apr-11 9:27am    
Do you want to do this within your code, at the database level? ie do you want the Access database to return the data pre-formatted. What have you tried so far?
Kschuler 15-Apr-11 11:20am    
I updated my solution with a bit more info on your font problem.

You could try this in your SQL:
SELECT LEFT(code & '           ', 11) as code, description FROM myFile


It concats eleven spaces to the end of the code, then grabs the first eleven characters of that string. So basically It's a pad right.

---- Added ----
For this to work, you'll need to set the font on your combo box to a monospaced font[^] like Courier New. Here is a list[^] of others.
 
Share this answer
 
v2
Comments
RaviRanjanKr 15-Apr-11 10:13am    
Nice Solution! My 5 :)
Dylan Morley 15-Apr-11 11:13am    
Comment from OP:

Thanks for your write but my problem exist.

The reason is not from your code but from the diffirend length from the letters
You see the letter f and the letter w has big difference and the description it
isn't straight with the description before and description after.

Did anyone has any idea to make the description absolutely straight........
Kschuler 15-Apr-11 11:21am    
Updated. Thanks for the relay reply.
Letter spacing (as you mentioned, letters such as m and w) are always going to be an issue.

You can tackle this in a couple of ways - use a monospaced font as mentioned by Kschuler or you could have your comobo box display multiple columns

There are a few articles on codeproject that show this

Multi Column ComboBox[^]

Flat-MultiColumn Combobox with Autocomplete[^]

Multi-Column ComboBox[^]

Then, you'd just set your column widths and load data in...it would always be aligned correctly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900