|
-
Mar 17th, 2010, 08:02 AM
#1
Thread Starter
New Member
Tidying up listbox
Hi im wondering can anyone help me I have all my details displayed in a listbox but when i run the code the listbox just doesnt look good everything continues from left to right across the listbox! as you will see from my code i have CustomerID, Forename, Surname, Street, Town, County, Telephone id like the next customers details to appear on the next line then not continuing along the same line.
I hope this makes sense and someone can help
Thanks
Heres my code:
Public Class AmendView
Private Sub AmendView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DisplayListBox(5)
End Sub
Private Sub DisplayListBox(ByVal num As Integer)
'Loads recordset & outputs to list box
Dim ConnectionString As String
Dim SQLString As String
Dim TitleString As String = " "
Dim conn As System.Data.OleDb.OleDbConnection
Dim dr As System.Data.OleDb.OleDbDataReader
Dim cmd As System.Data.OleDb.OleDbCommand
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data "
ConnectionString += "Source=" & "Opticians.accdb "
conn = New System.Data.OleDb.OleDbConnection(ConnectionString)
'Access the fields
SQLString = "SELECT CustomerID,Surname,Forename,Street,Town,COunty,Telephone FROM CustomerTable "
Try 'was database found etc.
cmd = New System.Data.OleDb.OleDbCommand(SQLString, conn)
conn.Open()
If (ConnectionState.Open.ToString = "Open") Then
dr = cmd.ExecuteReader()
If dr.HasRows Then
DisplayCustomersAmendViewListBox.Items.Clear()
While dr.Read
If Not IsDBNull(dr.Item("CustomerId")) Then
TitleString += dr.Item("CustomerID") & " "
TitleString += dr.Item("Surname") & " "
TitleString += dr.Item("Forename") & " "
TitleString += dr.Item("Street") & " "
TitleString += dr.Item("Town") & " "
TitleString += dr.Item("County") & " "
TitleString += dr.Item("Telephone") & " "
DisplayCustomersAmendViewListBox.Items.Add(TitleString)
End If
End While
End If
End If
Catch
MessageBox.Show("Error accessing database")
End Try
conn.Close()
DisplayCustomersAmendViewListBox.Items.Add(" ")
DisplayCustomersAmendViewListBox.Items.Add("Count:" & DisplayCustomersAmendViewListBox.Items.Count - 1)
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|