Results 1 to 6 of 6

Thread: string format zones

  1. #1

    Thread Starter
    Junior Member guitarhero14's Avatar
    Join Date
    Nov 2005
    Posts
    23

    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:
    1. 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.

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    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:
    1. Dim MyString As String = "Test"
    2.         MyString = MyString.PadRight(10, " "c) '10 characters, with space as padding character
    3.         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.

  3. #3

    Thread Starter
    Junior Member guitarhero14's Avatar
    Join Date
    Nov 2005
    Posts
    23

    Re: string format zones

    Thank you for your reply, it is exactly what i needed.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member guitarhero14's Avatar
    Join Date
    Nov 2005
    Posts
    23

    Re: string format zones

    Quote Originally Posted by jmcilhinney
    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
    i have never used listview before. I will look farther into it, thank you very much.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width