PC Review


Reply
Thread Tools Rate Thread

Data Binding Issue

 
 
Joseph Hanna
Guest
Posts: n/a
 
      28th Jul 2003
I have a table with 2 foreign keys in it that refer back to the same table.


Table 1: TM_CTP_Clocking_Type (Dataset = dsLookup)

CTP_ID Int (PK)
CTP_DESCRIPTION String


Table 2: TM_CLK_Clockings (Dataset = dsEmp)

CLK_ID Int (PK)
CLK_IN_CTP_ID Int (FK to Table 1)
CLK_OUT_CTP_ID Int (FK to Table 1)
CLK_FIELD1 String
etc...

I have a form with several Textboxes that are bound to other fields in Table 2 and they work fine. On the same form, I also have 2 Combo Boxes that are populated with Descriptions from Table 1, and the SelectedValue is set according to the value of the Foreign Keys in Table 2. My problem is at Runtime, both ComboBoxes are set to the same value (that of the second Combo box "cmbCLK_OUT_CTP_ID" - or second Data Binding?).

Here is my Data Binding code:


With Me.cmbCLK_IN_CTP_ID

.DataSource = dsLookup.TM_CTP_Clocking_Type
.ValueMember = "CTP_ID"
.DisplayMember = "CTP_DESCRIPTION"
.SelectedIndex = -1

.DataBindings.Clear()
.DataBindings.Add(New Binding("SelectedValue", dsEmp, "TM_CLK_Clockings.CLK_IN_CTP_ID"))

End With

With Me.cmbCLK_OUT_CTP_ID

.DataSource = dsLookup.TM_CTP_Clocking_Type
.ValueMember = "CTP_ID"
.DisplayMember = "CTP_DESCRIPTION"
.SelectedIndex = -1

.DataBindings.Clear()
.DataBindings.Add(New Binding("SelectedValue", dsEmp, "TM_CLK_Clockings.CLK_OUT_CTP_ID"))

End With

When I comment out the code for the second ComboBox's Data Binding, I get the correct result in the first Combo Box.

Am I doing something wrong in the code or is having 2 relationships to the same table too much for .NET Data Binding?


Many Thanks,
Joe

--

Joe Hanna
Advanced Software Engineering
joe.hanna_AT_advancedsoftware_DOT_net_DOT_au



 
Reply With Quote
 
 
 
 
Stephen Muecke
Guest
Posts: n/a
 
      28th Jul 2003
Joseph

You need to create 2 separate BindingContexts so that each combobox works
independently

Dim bc1 As New BindingContext()
Dim bc2 As New BindingContext()
firstCombo.BindingContext = bc1
secondCombo.BindingContext = bc2

Stephen

"Joseph Hanna" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
I have a table with 2 foreign keys in it that refer back to the same table.


Table 1: TM_CTP_Clocking_Type (Dataset = dsLookup)

CTP_ID Int (PK)
CTP_DESCRIPTION String


Table 2: TM_CLK_Clockings (Dataset = dsEmp)

CLK_ID Int (PK)
CLK_IN_CTP_ID Int (FK to Table 1)
CLK_OUT_CTP_ID Int (FK to Table 1)
CLK_FIELD1 String
etc...

I have a form with several Textboxes that are bound to other fields in Table
2 and they work fine. On the same form, I also have 2 Combo Boxes that are
populated with Descriptions from Table 1, and the SelectedValue is set
according to the value of the Foreign Keys in Table 2. My problem is at
Runtime, both ComboBoxes are set to the same value (that of the second Combo
box "cmbCLK_OUT_CTP_ID" - or second Data Binding?).

Here is my Data Binding code:


With Me.cmbCLK_IN_CTP_ID

.DataSource = dsLookup.TM_CTP_Clocking_Type
.ValueMember = "CTP_ID"
.DisplayMember = "CTP_DESCRIPTION"
.SelectedIndex = -1

.DataBindings.Clear()
.DataBindings.Add(New Binding("SelectedValue", dsEmp,
"TM_CLK_Clockings.CLK_IN_CTP_ID"))

End With

With Me.cmbCLK_OUT_CTP_ID

.DataSource = dsLookup.TM_CTP_Clocking_Type
.ValueMember = "CTP_ID"
.DisplayMember = "CTP_DESCRIPTION"
.SelectedIndex = -1

.DataBindings.Clear()
.DataBindings.Add(New Binding("SelectedValue", dsEmp,
"TM_CLK_Clockings.CLK_OUT_CTP_ID"))

End With

When I comment out the code for the second ComboBox's Data Binding, I get
the correct result in the first Combo Box.

Am I doing something wrong in the code or is having 2 relationships to the
same table too much for .NET Data Binding?


Many Thanks,
Joe

--

Joe Hanna
Advanced Software Engineering
joe.hanna_AT_advancedsoftware_DOT_net_DOT_au





 
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
Data Binding Issue KEN Microsoft C# .NET 0 11th Nov 2008 07:33 PM
100K item data binding: Is asynchronous data binding possible? R Reyes Microsoft C# .NET 14 5th Feb 2008 09:47 PM
Data Binding Issue Materialised Microsoft ASP .NET 0 20th Dec 2006 09:48 AM
Issue with Data Reader Binding for ASP.net ComboBox & Listbox cont =?Utf-8?B?U2FjaGluIEt1Y2hpbmFk?= Microsoft ASP .NET 1 22nd Jul 2004 01:20 PM
Data Binding issue Hollywood Microsoft Dot NET Compact Framework 1 15th Oct 2003 12:00 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:15 AM.