Complex databinding

  • Thread starter Thread starter Tim Tafflinger
  • Start date Start date
T

Tim Tafflinger

I'm using complex databinding with a combo box. When a
user retrieves a record from the database I want to be
able to set the valuemember to the value of the data
retrieved and have the corresponding displaymember
display. My controls using simple databinding, like text
boxes and single column combo boxes, is working great
using the code below. How do I do it with complex
databinding?

cboNewCarryover.DataBindings.Add
("Text",dsStatsSelect.Tables"tblPatientStats"), "PatientSta
tus")
 
Tim Tafflinger said:
cboNewCarryover.DataBindings.Add
("Text",dsStatsSelect.Tables"tblPatientStats"), "PatientSta
tus")

try
cboNewCarryover.DataSource = dsStatsSelect.Tables("tblPatientStats")
cboNewCarryover.DisplayMember = "YourDisplayField"
cboNewCarryover.ValueMember = "YourValueField"
 
I should clarify - I'm setting the DisplayMember and
ValueMember as you suggested and it's working well. The
combo box is displaying the values for the user to select
and I can read the ValueMember and write it to the
database. What isn't working is setting the combo box to a
value retrieved from an existing record in the database.
For example, if the DisplayMember and ValueMember pairs
are "1,Red;2,Green;3,Blue" and the user retrives a record
where that field has a value of 2, I can't get the combo
box to display Green. My combo boxes and text boxes using
simple binding are displaying the correct data so I know
the data is being retrieved ok.
 
Tim Tafflinger said:
For example, if the DisplayMember and ValueMember pairs
are "1,Red;2,Green;3,Blue" and the user retrives a record
where that field has a value of 2, I can't get the combo
box to display Green.

cbobox.selectedvalue = 2 doesn't work for you?
 
Sure, that works. I thought one of the advantages of
databinding though was that you didn't have to
programatically fill the values of your controls so all
you have to do is retrieve the record and the data is
displayed. It's working that way for all my controls using
simple databinding.
 
Here's a snippet for setting both DisplayMember &
ValueMember:

form.cboSondeEXMonRem.DataSource = ceDS.Tables
("Monitors_SondeEXRem")

form.cboSondeEXMonRem.DisplayMember = "MonAlias"
form.cboSondeEXMonRem.ValueMember = "SN"

Hope That Helps,

Scott
-----Original Message-----
I'm using complex databinding with a combo box. When a
user retrieves a record from the database I want to be
able to set the valuemember to the value of the data
retrieved and have the corresponding displaymember
display. My controls using simple databinding, like text
boxes and single column combo boxes, is working great
using the code below. How do I do it with complex
databinding?

cboNewCarryover.DataBindings.Add
("Text",dsStatsSelect.Tables"tblPatientStats"), "PatientSta
 
Well, it finally works! I moved the table I was having
problems with into the same dataset object as it's parent
table and used the code below as suggested by Mikael:

cboNewCarryover.DataBindings.Add
("SelectedValue",dsStatsSelect.Tables
("tblPatientStats")), "PatientStatus")

Probably obvious to everyone else I should have been using
the same dataset! Oh well, live and learn! Thanks!
-----Original Message-----
I'm using complex databinding with a combo box. When a
user retrieves a record from the database I want to be
able to set the valuemember to the value of the data
retrieved and have the corresponding displaymember
display. My controls using simple databinding, like text
boxes and single column combo boxes, is working great
using the code below. How do I do it with complex
databinding?

cboNewCarryover.DataBindings.Add
("Text",dsStatsSelect.Tables"tblPatientStats"), "PatientSta
 
Back
Top