|
-
Dec 14th, 2005, 07:27 PM
#1
Thread Starter
Junior Member
string format zones
I am having several items on one line of a listbox and i am setting up the zones. I have a problem with them staying aligned. I was wondering if there is a way to format that or else i am doing something wrong. Thank you.
VB Code:
Dim fmtstr As String = "{0,-30}{1,-25}{2,-25}{3,-10}{4,25}{5,30:N2}"
I have included a picture of what i mean.
-
Dec 14th, 2005, 08:53 PM
#2
Re: string format zones
Take a look at String Pad functions, like String.PadLeft, String.PadRight. It allows you to pad your strings with characters, like spaces. Basically each value that you posted would be padded to a certain amount of characters. After each one is padded, just concat them all into one string. For instance:
VB Code:
Dim MyString As String = "Test"
MyString = MyString.PadRight(10, " "c) '10 characters, with space as padding character
MsgBox("""" & MyString & """") 'displays "Test "
This puts 6 spaces at the end of Test, because the total width is 10 and the string length is 4. PadLeft would place the spaces on the left side. Basically you would do this for each one of your strings, then concat all of them into one final string before listing in the box.
-
Dec 14th, 2005, 11:24 PM
#3
Thread Starter
Junior Member
Re: string format zones
Thank you for your reply, it is exactly what i needed.
-
Dec 15th, 2005, 12:19 AM
#4
Re: string format zones
Why not just use a ListView instead, which supports real columns? Otherwise, you can get a multicolumn ListBox here: http://www.codeproject.com/cs/combob...umnlistbox.asp
-
Dec 15th, 2005, 03:24 AM
#5
Thread Starter
Junior Member
Re: string format zones
 Originally Posted by jmcilhinney
i have never used listview before. I will look farther into it, thank you very much.
-
Dec 15th, 2005, 03:41 AM
#6
Re: string format zones
What you see on the right-hand side of Windows Explorer is a ListView. You need to set the View property to Details to get columns.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|