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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox DataBinding not altering dataset

Status
Not open for further replies.

johnny2bad

Programmer
Nov 6, 2001
18
US
I have a VB.NET form that contains a ComboBox named "cmbWhseTerms".

And a dataset (dsDRF) that contains 2 tables:
"Header" - Contains header info.
"Terms" - Contains a list of possible shipping terms.

I created a relation between the two tables of the dataset using the "Terms" field in the header and the "Terms" field in the terms list:
Code:
dsDRF.Relations.Add("Terms", dsDRF.Tables("Terms").Columns ("Terms"), _ 
    dsDRF.Tables("Header").Columns("Terms"))

Then I set the data source of the combobox to the "Terms" table and then bound it to the "Terms" field in the header.
Code:
.cmbWhseTerms.DataSource = dsDRF.Tables("Terms")
.cmbWhseTerms.DisplayMember = "Terms"
.cmbWhseTerms.ValueMember = "Terms"
.cmbWhseTerms.DataBindings.Add(New Binding("Text", _ dsDRF.Tables("Header"), "Terms"))

The appropriate value will be selected when the form loads, but when I changed the value of the combobox dsDRF.Tables("Header").Columns("Terms") is not altered.

Any Ideas?



JohnD
"What we need is a list of specific unknown problems we will encounter.
 
Hey JohnD

Finally!! I've found a post that mentions the problem I'm having. I guess its because people bind to the SelectedValue property more than the Text property.

Did you find a solution to this by any chance? Its driving me slowly insane [bugeyed]

Cheers
Nells
 
Hey John,
Why don't you join the tables in your query before you load them into the dataset. Your code looks different than how i would load up a combobox, i use something like this

Dim dsRow As DataRow

For Each dsRow In dsItems.Tables("Items").Rows

lstItems.Items.Add(dsRow(0)) ' & ", " & dsRow(1))


Next

Well i hope this helps out somewhat, i'm still a bit confused with what your trying to do, let me know how this works out for you.
Sincerely,
Fritts
 
Nells,

The only thing I came up with was to use the validated event of the combobox to set the appropriate field in the "Header" table to equal the combobox's selected value.

Code:
dsDRF.Tables("Header").Rows(0)("Terms") = cmbWhseTerms.SelectedValue

I hope this helps. Please let me know if you come up with anything else.


JohnD
"What we need is a list of specific unknown problems we will encounter.
 
Hey JohnD

Yeah thats what I ended up with too.. I eventually wrote my own control that does it (as well as the auto complete fuctionality) so I didn't have to repeat the code for each combo box. Seems to work ok.. if you want a copy let me know.

Thanks for getting back to me [thumbsup]

Nells
 
Nells,

I'd love to see it. Anything to make my life a little easier.


JohnD
"What we need is a list of specific unknown problems we will encounter.
 
Hey JohnD

Having a few problems thinking of a way to get the control to you. Shall I just post the VB code here?? I should warn you, this is my first ever control, so its proably nowhere near perfect, but it seems to do the trick for me [thumbsup2]

Nells
 
Nells,

Do you have a web server that you could post the control on (in zip format perhaps)?


JohnD
"What we need is a list of specific unknown problems we will encounter.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top