PC Review


Reply
Thread Tools Rate Thread

Complex databinding

 
 
Tim Tafflinger
Guest
Posts: n/a
 
      25th Sep 2003
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")

 
Reply With Quote
 
 
 
 
khorad
Guest
Posts: n/a
 
      25th Sep 2003
"Tim Tafflinger" <(E-Mail Removed)> wrote in message
news:253c01c38378$175de710$(E-Mail Removed)...
> cboNewCarryover.DataBindings.Add
> ("Text",dsStatsSelect.Tables"tblPatientStats"), "PatientSta
> tus")


try
cboNewCarryover.DataSource = dsStatsSelect.Tables("tblPatientStats")
cboNewCarryover.DisplayMember = "YourDisplayField"
cboNewCarryover.ValueMember = "YourValueField"


 
Reply With Quote
 
Tim Tafflinger
Guest
Posts: n/a
 
      25th Sep 2003
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.

>-----Original Message-----
>"Tim Tafflinger" <(E-Mail Removed)> wrote in

message
>news:253c01c38378$175de710$(E-Mail Removed)...
>> cboNewCarryover.DataBindings.Add
>>

("Text",dsStatsSelect.Tables"tblPatientStats"), "PatientSta
>> tus")

>
>try
>cboNewCarryover.DataSource = dsStatsSelect.Tables

("tblPatientStats")
>cboNewCarryover.DisplayMember = "YourDisplayField"
>cboNewCarryover.ValueMember = "YourValueField"
>
>
>.
>

 
Reply With Quote
 
khorad
Guest
Posts: n/a
 
      25th Sep 2003
"Tim Tafflinger" <(E-Mail Removed)> wrote in message
news:10d8001c38381$1f694b80$(E-Mail Removed)...
> 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?


 
Reply With Quote
 
Tim Tafflinger
Guest
Posts: n/a
 
      25th Sep 2003
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.

>-----Original Message-----
>"Tim Tafflinger" <(E-Mail Removed)> wrote in

message
>news:10d8001c38381$1f694b80$(E-Mail Removed)...
>> 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?
>
>
>.
>

 
Reply With Quote
 
Scott Fredrick
Guest
Posts: n/a
 
      25th Sep 2003
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
>tus")
>
>.
>

 
Reply With Quote
 
Tim Tafflinger
Guest
Posts: n/a
 
      25th Sep 2003
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
>tus")
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Complex databinding Craig Buchanan Microsoft ASP .NET 1 27th May 2008 07:20 AM
WPF: Complex Databinding J.Marsch Microsoft C# .NET 0 15th Mar 2008 06:04 PM
ComboBox databinding - complex Mike Microsoft ADO .NET 1 17th Oct 2006 05:20 AM
Complex databinding with ASP Listbox Ray Valenti Microsoft ASP .NET 1 1st Dec 2003 03:54 PM
Complex databinding with ASP Listbox Ray Valenti Microsoft ADO .NET 1 1st Dec 2003 03:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:14 PM.