English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I want to display a string array in listbox, align properly every line, vbTab cannot be used if one of the string is longer, as following

Andrew 77 88 99
Jane 93 76 34
Christopher 56 76 88
Lily 54 68 73

Please help....!

2007-02-10 11:34:35 · 2 answers · asked by bfughinehllai 1 in Computers & Internet Programming & Design

2 answers

A couple of things you will need to do.
First use a fixed font like Courier New, this font uses the same width for each character unlike a proportional font which varies the width of characters. Using a font with a fixed charcter width will help keep all characters lined up.

Next you will have to reassemble each string in the array so each field of data has the same number of characters. You can do this with another string array and the split function.

Doing this will allow you to make each name field the same size by padding each name with whiespace. There are padLeft and padRight string functions which will add a number of spaces to either the left or right side of a string to make the total lenght a set number. So make the name field 15 characters wide :
str = "Jill"
str = str.padright(15)
str becomes "Jill "

pad each field in your string so that it becomes a standardizes width and concatenate the field back into a single string and reload into the original string array.

Now when you load these padded strings with a fixed font all of the field will line up in the list box.

2007-02-10 17:25:58 · answer #1 · answered by MarkG 7 · 0 0

Sadly the Listbox control does not have that capability of aligning. I've always yearned for such a feature. The best option for you would be to use a "custom-built" listbox control that incorporates that featue. I have seen custom listboxes that do this around the net. The other option is to subclass the listbox control and then upon drawing the listbox it would take the text and notice a tab and draw the text at specific locations...I use to do subclassing alot in C++ and after u get the hang of things and drawing it is quite simple...In VB it does have subclassing but it can be a little bit tricky but still doable...easiest solution is to get a custom control.

2007-02-10 14:45:40 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers