Wrox Programmer Forums
|
.NET Framework 1.x For discussing versions 1.0 and 1.1 of the Microsoft .NET Framework.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 1.x section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 28th, 2007, 02:01 PM
Authorized User
 
Join Date: Sep 2007
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default Listbox Values using VB.net

i'm using vb.net.

i have a Listbox that contains items like this.

Quote:
quote:
Peter Mathew [2000] [200]
Mathew [1000] [2]
Thomas John Mathew [200] [5]
James John [500] [6]
i need to align this to this format.

Quote:
quote:
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.

Code:
            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.
 
Old February 15th, 2008, 10:49 AM
Registered User
 
Join Date: Feb 2008
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

One problem i can think of in the displayed format is the length of the name.We once had a similar issue.We ended up having an algorithm to trim the names as well as one to put in special characters

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

In this format,what should happen if my name is musclebai musclebai musclebai musclebai...yes that long one....then it will have to be trimmed at some point....say musclebai mu..mu..mu.. or something similar.
We can have say 50 characters designated for name and fill up the rest of the unoccupied 50 with blank spaces.






Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple Listbox values in another listbox terryv Excel VBA 0 June 27th, 2007 07:01 AM
Using Values from a ListBox timmaher Classic ASP Databases 2 September 14th, 2005 10:01 AM
Inserting Values in Database OracleCommand VB.NET narendra_patil BOOK: Beginning ASP.NET 1.0 0 April 22nd, 2005 07:35 AM
Getting Values From ListBox DARSIN General .NET 2 October 1st, 2004 02:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.