I Need Help With Drop Down List Boxes

i was wondering if someone knew how to set drow down list boxes = a value in the table that is pulled up by the main drop down list box.

I have a tracking No ddl that is sopposted to populate the entire table with the values for that record in the table. i have it where it will fill in the text boxes but the other ddls in the table are being filled by other tables that are f-keys in the trackingNo table. I now need the trackingNo DDL to select the right value for the other tables. here is the code for the ddlTrackingNo and see if that helps you help me...

Please any help is welcomed....

Thanks,

WoFe

Private Sub ddlrackingNo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlTrackingNo.SelectedIndexChanged
Dim trackingno As String
trackingno = ddlTrackingNo.SelectedItem.Text
SqlGoToTrackingNo.Parameters("@trackingno").Value = trackingno
SqlConnection1.Open()
Dim dreader As SqlClient.SqlDataReader
dreader = SqlGoToTrackingNo.ExecuteReader(CommandBehavior.SingleRow)
If dreader.Read() Then
txtLastUpdate.Text = dreader("LastUpdate").ToString()
txtWorkNumber.Text = dreader("WorkNumber").ToString()
txtDateReceived.Text = dreader("DateReceived").ToString()
End If
dreader.Close()
SqlConnection1.Close()

hmm.. okay another thing.. i was trying to hard code a selected value into the ddl box and it gave me "A DropDownList cannot have multiple items selected." error...

ddlCity1.Items.FindByValue("Avon Park").Selected = True

[1651 byte] By [WoFe] at [2007-12-23]
# 1

Are you using databinding with the dropdown list box.

If you are you cant simply add items to the dropdownlist items collection - you need to add a record to the data source. which is probably a dataset/datatable. In which case add the item here and it will be reflected in the drop down list.

Remeber the dataset is a in-memory snapshot and this additional record wont be persisted to the database until you issue a update method on the table adapter used to populate the dataset. So if you dont issue this the changes are only temporary in-memory when the dataset is in scope. If you restart your application and repopulate from the database - that added item wont be there.

The dropdownList is a combobox which doesnt have a multi-select property. You would need to use a normal listbox to have multiple selections available.

spotty at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

the ddlTrackingNo value is the Primary key on the table in which everything is being populated by. The ddlCity is being filled by another table but i want it to have the value selected as it is listed in the table with ddlTrackingNo. for instance

tblFood

ITEM INGED FLAVOR
candy sugar sweet
steak beef bold

tblFlavor

FLAVOR DESCRIPTION
sweet enter desc
bold enter desc
sour enter desc

Form

|ddl from tblFlavor |--> bold
Item Name: (Candy) Inged: (Sugar) Flavor: (sweet)
sour

WoFe at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3
i already have ddlcity being populated.. i just want it to have the correct selected value then i click on a trackingno inside of the ddltrackingno
WoFe at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

You can set the ddlcity selected item - either via the SelectedItem, SelectedIndex or SelectedValue properties.

These I assume would be based upon some value you achieve from a change in the ddltrackno drop down list. Which you appear to have some coding in the ddltrackingno.SelectedIndexChanged event.

spotty at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5

In the form there is a Main drop down list where the end-user choices a tracking number. That tracking number they choose then fills the entire form giving all the other objects the value that is in the table for the tracking number. In the form there is a drop down list that has a list of cities we serve in it, that list is pulled up from another table. I need the form when the end-user chooses a tracking number to then select the correct city in the city drop down list that is listed for city in the tracking number table.

All the cities in the city table are cross referenced to the city in the tracking number table. The code I was trying to use was something like this at the end of the ddltrackingno_SelectedIndex

ddlCity.SelectedIndex = dreader("City").ToString()

It gives me an error... Input string was not in a correct format. So I am not sure what next...

WoFe at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6
Okay well I finally figured out what to do about the drop down list boxes...

Code:

ddlCity.SelectedValue = dreader("City").ToString()

and it worked for the ddl box...

Now i need help trying to figure how how to get my list box working... In the form i am making there is a list box that "IN MS Access" the person was able to add comments in the list box about the TrackingNo. so now i need to made it so that when the end-user picks a tracking number from the drop down list... the Memo List box is filled with the data from the table that goes with the Tracking number.

Then i need to make it so that the end-user can add to the list box for the tracking number and save it back to the table.

WoFe at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 7

So selectedvalue property worked for you. There are many ways to select items which is reflected in the methods available.

This sounds like when they select a tracking number - you are going to issue a SQL command to retrieve the items on the tracking number. And once you have this you can iterate through the items returned and add them to the Memo Listbox.

I'd use a dataset and table adapter rather than a SQL reader. Then you simply add a record to the dataset and when you ready to commit the changes to the database you issue a call to the tableadapter update method.

Numerous examples of dataset and updating records - a simple web search on VB.Net + Dataset

It looks like you just need to add the populate memo listbox code when a tracking number is selected in the dropdown list. And add a couple of buttons to add the new items to the memo items dataset / database table.

spotty at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 8

thanks for the ideas....

so datasets are better than using SQL commands? I am still very new the the whole idea of programming... only 2 weeks into it so i guess iam doing it the hard way.. but... hey.. it worked.. lol.. i am going to take a look at datasets and see if in future forms... * i have probably close to a 100 forms to convert from MS Access to VB.net and over 200 different reports to convert also... so i will probably become a regular here and at all the other vb.net forums of the world...

WoFe at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...