|
|
 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the WinForms/Console Application Design section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other programmers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
|
 |

July 1st, 2009, 12:34 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2008
Location: london, , United Kingdom.
Posts: 153
Thanks: 7
Thanked 1 Time in 1 Post
|
|
How to bind a ListBox to datadase
I need a way to display 3 columns data in ListBox
I Have this code:
Code:
Dim cnn As SqlConnection = New SqlConnection("Data Source=SQL1;Initial Catalog=Tracking;Integrated Security=True")
' Connect to the database
' Create a new ad hoc query to retrieve customer names
Dim cmd As SqlCommand = cnn.CreateCommand
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT CNAM05 , CUSN05 , PCD105 FROM table1 Where (CNAM05 Like '" & TextBox1.Text & "%')"
' Dump the data to the user interface
cnn.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader
DoWhile dr.Read()
ListBox1.Items.Add(dr.GetString(0))
Loop
' Clean up
dr.Close()
cnn.Close()
this returns data from 1 column, I need to display Name -- Address--Post Code. but when i select an item only the value of name should be past
thanks in advance
__________________
bx
Last edited by bex : July 1st, 2009 at 04:39 PM.
|

July 4th, 2009, 05:01 AM
|
 |
Wrox Author
Points: 35,654, Level: 82 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,575
Thanks: 12
Thanked 284 Times in 280 Posts
|
|
Hi there,
You can concatenate the values you need in the query and then display them:
SELECT Name + ' (' + Address + ')' AS FullDescription, Name FROM Table
Then you can use FullDescription as the text for the drop down and Name for the value.
You can also query them as separate columns (Name, Address) and then concatenate them in your VB code.
Hope this helps,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|

July 4th, 2009, 11:35 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2008
Location: london, , United Kingdom.
Posts: 153
Thanks: 7
Thanked 1 Time in 1 Post
|
|
Thanks Imar
that works fine,
now it dysplays like this
Name ------------------Address------------------------ Postcode
Name --------------------------------Address------------------------------ Postcode
Name ---------Address -----------------------------------Postcode.....
it will be nice if i can disply the query in columns:
Name Address Postcode
Name Address Postcode
Name Address Postcode
__________________
bx
Last edited by bex : July 4th, 2009 at 04:57 PM.
|

July 5th, 2009, 05:09 AM
|
 |
Wrox Author
Points: 35,654, Level: 82 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,575
Thanks: 12
Thanked 284 Times in 280 Posts
|
|
Hi bex,
This is not so easy to implement. Browsers don't support multi columns in a drop down list and strip multiple spaces from the items in the list so you can't use spaces to fill up the items.
There are a number of solutions available; some free and some paid:
http://www.google.com/search?hl=en&q...n+drop+&aqi=g5
Cheers,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |