Listbox Values

remya1000

Well-known member
Joined
Mar 29, 2007
Messages
122
Programming Experience
Beginner
i'm using vb.net.

i have a Listbox that contains items like this.

Peter Mathew [2000] [200]
Mathew [1000] [2]
Thomas John Mathew [200] [5]
James John [500] [6]

i need to align this to this format.

Peter Mathew-------------[2000]-----[200]
Mathew-------------------[1000]-----[2]
Thomas John Mathew------[200]------[5]
James John---------------[500]------[6]

"----" means space between name and that number. consider "---" as space. i don't need to dispaly "----". instead of "---" i need space in listbox between each items.

i gave "----" for you to understand the format. because when i gave the sapce and save the post, its not showing those space.
This is the code i'm using to display items inside listbox. i'm taking values from different tables and sorting that and display it to ListBox.

VB.NET:
            Dim pArray As New ArrayList

           Dim myConnection As New OleDbConnection(strConn)
            myConnection.Open()

            Dim schemaTable As DataTable
            'This will get all the table names from Database to DataTable
            schemaTable = myConnection.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})

            'Dim Table1 As DataTable = New DataTable("Orders")
            Table1 = New DataTable("Orders")
            Dim Row As DataRow

            Dim Description As DataColumn = New DataColumn("Description")
            Table1.Columns.Add(Description)

            Dim Group As DataColumn = New DataColumn("Group")
            Group.DataType = System.Type.GetType("System.Int32")
            Table1.Columns.Add(Group)

            Dim i As Integer
            For i = 0 To schemaTable.Rows.Count - 1
                Dim NotInArray As Boolean = True

                'Taking Each Table Name from DataTable
                Dim pTableName As String = schemaTable.Rows(i)!TABLE_NAME.ToString

                'Checking the table names Starts with "MG"
                If Microsoft.VisualBasic.Left(pTableName, 2) = "MG" 
                    Dim strSQL As String = "Select Description, Group, pl1 from " & pTableName & " where [Group] <> 0"
                    Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, myConnection)
                    Dim myReader As OleDbDataReader = myCommand.ExecuteReader
                    While myReader.Read
                            Row = Table1.NewRow()
                            Row("Description") = Trim(myReader(0)) & "   [" & myReader(1) & "]" & "  [" & myReader(2) & "]"
                            Table1.Rows.Add(Row)
                        End If
                    End While
                    myReader.Close()
                End If
            Next
            myConnection.Close()

            Dim objDataView As New DataView(Table1)
            objDataView.Sort = "Description ASC"
            ListBox1.DataSource = objDataView
            ListBox1.DisplayMember = "Description"
            ListBox1.ValueMember = "Group"
            ListBox1.SelectedValue = ""

if you have anyidea how to align this please help me. and if you can provide an example that will be great helpful for me.

thanks in advance.
 
ListView or DataGrid controls are better suited to display multi-column tabular data.
But if you for some reason want to do Listbox anyway, then use such a font and String.Format to align the "columns" within the string.
 
Thanks a lot for the help. now i can align the ListView and i gave the font courier new.

Once again thanks a lot for the help.
 
Back
Top