Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. formatting of data in list box in vb 2008

formatting of data in list box in vb 2008

Scheduled Pinned Locked Moved Visual Basic
tutorial
8 Posts 4 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sazd1
    wrote on last edited by
    #1

    I am new to vb 2008. i have four textboxes. and the data is displayed in a listbox in four columns. but the columns are not formatted. like the data shows like this. Order1 23 3 23.2 new order1 25 3 54 Order4 54 4 52.3 as you see the columns are not formatted. kindly advise me how to format columns in listbox so that data is aligned in a proper format.

    L H 2 Replies Last reply
    0
    • S sazd1

      I am new to vb 2008. i have four textboxes. and the data is displayed in a listbox in four columns. but the columns are not formatted. like the data shows like this. Order1 23 3 23.2 new order1 25 3 54 Order4 54 4 52.3 as you see the columns are not formatted. kindly advise me how to format columns in listbox so that data is aligned in a proper format.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Use a fixed-width font, such as "Courier New" :)

      I are troll :)

      S 1 Reply Last reply
      0
      • S sazd1

        I am new to vb 2008. i have four textboxes. and the data is displayed in a listbox in four columns. but the columns are not formatted. like the data shows like this. Order1 23 3 23.2 new order1 25 3 54 Order4 54 4 52.3 as you see the columns are not formatted. kindly advise me how to format columns in listbox so that data is aligned in a proper format.

        H Offline
        H Offline
        Henry Minute
        wrote on last edited by
        #3

        Google for TabbedListbox

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        1 Reply Last reply
        0
        • L Lost User

          Use a fixed-width font, such as "Courier New" :)

          I are troll :)

          S Offline
          S Offline
          sazd1
          wrote on last edited by
          #4

          thanks for your advice. I tried that font of COURIER NEW. but the result is same. the columns data is not formatted. kindly give some other idea. or is there any option in listbox properties to align the data in columns.

          L 1 Reply Last reply
          0
          • S sazd1

            thanks for your advice. I tried that font of COURIER NEW. but the result is same. the columns data is not formatted. kindly give some other idea. or is there any option in listbox properties to align the data in columns.

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Using a different font won't change the formatting. You can add spaces to the text so that it aligns nicely. Not a good solution, but rather a quick-fix. A better solution is provided here[^], based on the MultiColumn property, along with a sample. This puts items in multiple columns, but those can't be considered as rows - it's a list of multiple items that continues on the second column once the first column runs out of rows. Lastly, you could consider exchanging the ListBox for a ListView. That one does columns :)

            I are troll :)

            S 1 Reply Last reply
            0
            • L Lost User

              Using a different font won't change the formatting. You can add spaces to the text so that it aligns nicely. Not a good solution, but rather a quick-fix. A better solution is provided here[^], based on the MultiColumn property, along with a sample. This puts items in multiple columns, but those can't be considered as rows - it's a list of multiple items that continues on the second column once the first column runs out of rows. Lastly, you could consider exchanging the ListBox for a ListView. That one does columns :)

              I are troll :)

              S Offline
              S Offline
              sazd1
              wrote on last edited by
              #6

              so there is no option for alignment of data in columns in listbox. to add spaces is difficult. because the data is being transferred from tables and there is text of different in each row and column. like: Coca Cola Normal Sprite Fanta Pepsi Coca Cola Zero so it is not possible to add spaces. can anybody have any idea to fix the problem of aligning the data in columns in listbox in vb2008

              D L 2 Replies Last reply
              0
              • S sazd1

                so there is no option for alignment of data in columns in listbox. to add spaces is difficult. because the data is being transferred from tables and there is text of different in each row and column. like: Coca Cola Normal Sprite Fanta Pepsi Coca Cola Zero so it is not possible to add spaces. can anybody have any idea to fix the problem of aligning the data in columns in listbox in vb2008

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                ListBox supports a MultiColumn[^] property that sounds like it might do what you need.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008

                1 Reply Last reply
                0
                • S sazd1

                  so there is no option for alignment of data in columns in listbox. to add spaces is difficult. because the data is being transferred from tables and there is text of different in each row and column. like: Coca Cola Normal Sprite Fanta Pepsi Coca Cola Zero so it is not possible to add spaces. can anybody have any idea to fix the problem of aligning the data in columns in listbox in vb2008

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  sazd1 wrote:

                  so there is no option for alignment of data in columns in listbox.

                  It's meant as a list. If you try this;

                  ListBox1.MultiColumn = True
                  Dim i As Integer
                  For i = 1 To 40
                  ListBox1.Items.Add("Test " & i)
                  Next i

                  You'll get a list of multiple items, stacked like this (that's assuming that your list has a height that has enough room for six items);

                  Test 1 Test 7 Test 13
                  Test 2 Test 8 Test 14
                  Test 3 Test 9 Test 15
                  Test 4 Test 10 Test 16
                  Test 5 Test 11 Test 17
                  Test 6 Test 12 Test 18

                  sazd1 wrote:

                  to add spaces is difficult.

                  I have made you a short example on that;

                      \[...\]
                      ListBox1.MultiColumn = False
                      ListBox1.Font = New Font( \_
                          System.Drawing.FontFamily.GenericMonospace, \_
                          ListBox1.Font.Size, \_
                          ListBox1.Font.Style, \_
                          ListBox1.Font.Unit)
                      Dim j As Integer
                      For j = 1 To 20
                          ListBox1.Items.Add(AsFixedColumnText("Test " & j, 8) & \_
                                             Space(3) & \_
                                             AsFixedColumnText(Date.Now(), 8) & \_
                                             Space(3) & \_
                                             AsFixedColumnText("Hello", 3))
                      Next j
                  
                  End Sub
                  
                  Public Function AsFixedColumnText(ByVal text As String, ByVal length As Integer)
                      If String.IsNullOrEmpty(text) Then
                          Return Space(length)
                      Else
                          Return (text & Space(length)).Substring(0, length - 1)
                      End If
                  End Function
                  

                  This should give you an output that's formatted in columns, similar to this;

                  Test 1 5/7/200 He
                  Test 2 5/7/200 He
                  Test 3 5/7/200 He
                  Test 4 5/7/200 He
                  Test 5 5/7/200 He
                  Test 6 5/7/200 He
                  Test 7 5/7/200 He
                  Test 8 5/7/200 He
                  Test 9 5/7/200 He
                  Test 10 5/7/200 He
                  Test 11 5/7/200 He
                  Test 12 5/7/200 He
                  Test 13 5/7/200 He
                  Test 14 5/7/200 He
                  Test 15 5/7/200 He
                  Test 16 5/7/200 He
                  Test 17 5/7/200 He
                  Test 18 5/7/200 He
                  Test 19 5/7/200 He
                  Test 20 5/7/200 He

                  Still, I don't think that this is the ideal solution. Is there any way that you can promote the ListBox to a ListView? Or even a DataGridView?

                  I are troll :)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups