 |
| VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1). |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB.NET 2002/2003 Basics 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
|
|
|
|

August 1st, 2005, 03:46 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Using ado.net and data binding
Hi all,
I am really battling with an application and would be most grateful if anyone could give me some pointers.
I need to create a program to view orders placed by customers.
They have asked for 2 screens.The first will allow a selection of a customer ID from a drop down list box.The screen will then display all the selected customer details(first name, last name, city ,state zip, code) in read only textboxes.A data grid will also be on this screen to show all orders place by this customer.None of this data will be editable.This application is purely for viewing purposes.
I do hope someone can shed some light on this for me and thank you in advance for taking some time out to give me a hand.
Kind regards
George
|
|

August 1st, 2005, 09:14 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
What exactly do you want help with? It sounds like you have mapped out what you need to do...
|
|

August 2nd, 2005, 07:42 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am wanting to bind six names from a dataset to my dropdown combobox.
Regards
Brett
|
|

August 2nd, 2005, 08:28 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
Is that the total contents of your dataset, or do you have more names than that?
|
|

August 3rd, 2005, 09:53 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Sorry for being so vague, just really confused. what I need to do first of all is to bind my dropdown combobox to my database which has first name, last name, city, state and zip code.
B
|
|

August 3rd, 2005, 12:26 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
If you already have your dataset filled, then you can simply set 2 properties of the combobox:
'note: don't include the square brackets...
ComboBox1.DataSource = ds.Tables("[TableName]") 'this is the name of the table in the dataset
ComboBox1.DisplayMember = "[ColumnName]" 'this is the name of the column to bind to
---------------------------------------------
However, I have had various problems when binding comboboxes so I choose not to do it. Instead, I loop through the dataset and add items manually to the combobox. Slightly more work but it allows much more flexibility and I don't have the same issues.
J
|
|

August 4th, 2005, 04:01 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks so much for your help.....
What I need to do now i think is to use the currency manager to display the relevent deatils in my 5 textboxes.
When i click on the combobox drop down list and select customerID1,the first name, last name, city, state and zip code need to appear in my 5 readonly text boxes...If I select customerID 4 then those particular details need to apperar...etc...etc
Any further help would be very much appreciated and thanks again for taking time out to lend me a hand.
Regards
B
|
|

August 4th, 2005, 08:59 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
I haven't used the currency manager...
What you can do is use the same dataset, but instead of populating it with only the single field, populate it with all of the fields that you require. Then when the selected index of the first textbox changes you can set the text property to the fields you want. The reason you can do this is that your dataset is indexed at 0 and so is your combobox.
So, if the user selects an item in the combobox it would look something like this:
Textbox1.Text = ds.Tables("TableName").Rows(ComboBox1.SelectedInde x).Item(1)
'assuming item 1 is the 2nd field in your row - 1 would likely be the field in the combobox
Textbox2.Text = ds.Tables("TableName").Rows(ComboBox1.SelectedInde x).Item(2)
Textbox3.Text = ds.Tables("TableName").Rows(ComboBox1.SelectedInde x).Item(3)
Textbox4.Text = ds.Tables("TableName").Rows(ComboBox1.SelectedInde x).Item(4)
Textbox5.Text = ds.Tables("TableName").Rows(ComboBox1.SelectedInde x).Item(5)
etc...
I have substituted generic names for your objects because I don't know what they are - change them accordingly.
And, the final thing is to put this in the SelectedIndexChanged event of the combobox (ComboBox1).
J
|
|

August 4th, 2005, 10:49 AM
|
|
Authorized User
|
|
Join Date: Sep 2004
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What can I say....You are a genius !! Thank you so very much for all of your help.
B
|
|

August 4th, 2005, 01:19 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
Your welcome!
|
|
 |