order to provide in listbox

zabo

New member
Joined
Aug 26, 2010
Messages
2
Programming Experience
1-3
hi guys, i have a problem and my project is stop now so i must solve this problem with ur help please.
i have a listbox in my project and simple is;

sorunp.jpg


so this infos are irregular. i getting this infos with a loop into listbox. i want this infos be sub-bottom.

i want this ;

duzgun.jpg


thank you very much for your helps :)
 
Last edited:
You can use String.Format and provide fixed widths for each column you want. You'll also need to use a fixed width font such a Courier New for it to look right.

VB.NET:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.ListBox1.Items.Add(String.Format("{0,-10}{1,-10}{2,-3}", "Name", "Surname", "Age"))
        Me.ListBox1.Items.Add(String.Empty)
        Me.ListBox1.Items.AddRange(New List(Of String)() From
                                   {
                                       New Person("a", "bc", 18).FormatString,
                                       New Person("ab", "bcd", 25).FormatString,
                                       New Person("abcd", "bcde", 33).FormatString,
                                       New Person("abcde", "bcdef", 45).FormatString
                                   }.ToArray)
    End Sub
End Class

Friend Class Person
    Property Name As String
    Property Surname As String
    Property Age As Integer

    Public Sub New(ByVal name As String, ByVal surname As String, ByVal age As Integer)
        _Name = name
        _Surname = surname
        _Age = age
    End Sub
End Class

Module PersonHelper

    <System.Runtime.CompilerServices.Extension()>
    Public Function FormatString(ByRef thePerson As Person) As String
        Return String.Format("{0,-10}{1,-10}{2,-3}", thePerson.Name, thePerson.Surname, thePerson.Age)
    End Function

End Module
 
Back
Top