Click to See Complete Forum and Search --> : Quick question about adding whitespace to a string


hangman
February 27th, 2006, 08:39 AM
Hi everyone, I'm working on this project where I need to have tons of comboboxes with certain numbers and codes in them. Every one of these codes has a certain description and I would like to show them all this way:

"code | description"

Now, the problem with this is when the codes have different lengths. Usually it only differs one char, so I thought it was just a matter of adding a little check on the length of the code and then adding a blank in front of the "|" when the code had the shorter form, but the problem with this is that it just never alligns nicely. There will always be two or three pixels of difference between the length in front of the "|" for the shorter and the longer form of the code.

If anyone has any suggestions (adding a certain length of white pixels for example, although I think this might be a bit far fetched) or any other ways to display the codes and descriptions nicely, I'd be immensely greatful!

Thanks in advance!!

Krzemo
February 27th, 2006, 08:54 AM
1) U can do "owner drawing" in ComboBox to achieve that (more to do but it can look very cool

2) U can use fixed pitch font like "Courier New" for example (easy way) and than U have to make all strings equal in count of characters.

Best regards,
Krzemo.

HanneSThEGreaT
February 27th, 2006, 09:20 AM
Just for interest sake, I think you can use the Space (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctspace.asp) function, once you have determinde the length of the first string, to add spaces in front of the second string

venAdder
February 27th, 2006, 12:06 PM
try looking into padright and padleft functions of string class

jmcilhinney
February 28th, 2006, 02:17 AM
Padding strings with spaces won't do you much good unless you're using a fixed-width font. This (http://www.codeproject.com/vb/net/multicolumncombo.asp) is exactly what you want.

hangman
February 28th, 2006, 05:19 AM
Thank you all for the help! It took me a day or so to finetune the owner drawn combobox, but it looks great now, I'm glad I didn't go for the easy way :P

For those of you who are interested in this matter, I think this article (http://www.devx.com/dotnet/Article/8014/0/page/3) is very useful too.

Thanks for the "Space" function too, I didn't know it existed and it sure is a lot easier to count the spaces in "Space(10)" then in " " :)

jmcilhinney
February 28th, 2006, 06:49 AM
There is no Spaces class. Space is a function, specifically the Microsoft.VisualBasic.Strings.Space function.

hangman
February 28th, 2006, 07:28 AM
Who said anything about a space class? :p

I just tend to mix up those names, a space class would be quite silly I think, so it was even more silly of me not to see that I had written it wrong...