Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combobox datasource

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
I am trying to resolve an issue with a combobox datasource. I have managed to set the source for the combobox to a data source that I have added to the project and it is displaying the full list of options in the combobox.

However, I have another dataset and I want to use the value in one of those fields to specify the selection option within the combobox. I have tried binding this field to the selecteditem, selectedvalue and text fields under the databindings section of my combobox properties but none of these appeared to work.

Mighty
 

How are you creating and binding the data source to the combobox?



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
In all my workings with ComboBoxes, they only accept a single DataSource at a time. You cannot mix and match. You need to combine the 2 DataTables into a single DataTable.

Think of it this way: How does the ComboBox know how to join the two DataTables together? Just because item A is selected, there is nothing that ties it to value A unless they are in the same DataTable.

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
I have a dataset which I set as the datasource for my conboxbox and set the relevant display member so that the comboxbox display all the values from this dataset as options in the combobox.

However, the combobox is a field within a datarepeater that is bound to a larger dataset. What I would like to be able to do is populate the combobox with the options from the above dataset but select the value that is already stored in a field in the dataset that my datarepeater is bound to.

Hope I explained that correctly.

Mighty
 
Could you please post what code you have so we can point you in the right direction?

Typically the following works (InqDt is a DataTable):
Code:
cmbPayType.SelectedValue = InqDt.Rows(0).Item("PayTypeId")

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
Managed to get this sorted by just adding the items to the Combobox using the ItemCloned event handler. Just added in the following code:

Code:
Cmb = e.DataRepeaterItem.Controls("Visual_Inspection_1ComboBox")
Cmb.Items.AddRange(New String() {"Pass", "Aggregate", "Bare Spots", "Dropped", "Fibres", "Foreign Material"})

This added all the options to my list and as the field was data bound to my dataset, it automatically selected the correct option from the list where appropriate. Works a charm.


However, now I have another question in relation to accessing fields within the datarepeater (which I like by the way). I have a click event handler on a label in my datarepeater which reads a weight from an externally updated scales and then updates the text of the label that was clicked on and the one beside it.

So how do I find out what row of the datarepeater contains the label that was clicked on and how to I reference another field on that row?

Mighty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top