This is a multi-part message in MIME format.

------=_NextPart_000_0008_01C35525.89B187D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I have a table with 2 foreign keys in it that refer back to the same =
table.


Table 1: TM_CTP_Clocking_Type (Dataset =3D dsLookup)

CTP_ID Int (PK)
CTP_DESCRIPTION String


Table 2: TM_CLK_Clockings (Dataset =3D 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... =20

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:=20


With Me.cmbCLK_IN_CTP_ID

.DataSource =3D dsLookup.TM_CTP_Clocking_Type
.ValueMember =3D "CTP_ID"
.DisplayMember =3D "CTP_DESCRIPTION"
.SelectedIndex =3D -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 =3D dsLookup.TM_CTP_Clocking_Type
.ValueMember =3D "CTP_ID"
.DisplayMember =3D "CTP_DESCRIPTION"
.SelectedIndex =3D -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

--=20

Joe Hanna
Advanced Software Engineering
joe.hanna_AT_advancedsoftware_DOT_net_DOT_au



------=_NextPart_000_0008_01C35525.89B187D0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1170" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>I have a table with 2 foreign keys in it that refer =
back to=20
the same table.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Table 1:&nbsp; =
TM_CTP_Clocking_Type&nbsp;=20
(Dataset =3D dsLookup)</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;=20
CTP_ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;Int&nbsp;&nbsp;&nbsp;(PK)</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;=20
CTP_DESCRIPTION&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Table 2:&nbsp;=20
TM_CLK_Clockings&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Dataset =3D=20
dsEmp)</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;=20
CLK_ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;Int&nbsp;&nbsp;&nbsp;(PK)</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;=20
CLK_IN_CTP_ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Int&nbsp;&nbsp; =
(FK to=20
Table 1)</FONT></DIV>
<DIV><FONT size=3D2>
<DIV><FONT face=3D"Courier New" size=3D2>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;=20
CLK_OUT_CTP_ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Int&nbsp;&nbsp;&nbsp;(F=
K to=20
Table 1)
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;=20
&nbsp;&nbsp;&nbsp;=20
CLK_FIELD1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Str=
ing</FONT></DIV>
<DIV></FONT></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e=
tc...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</DIV></DIV></DIV></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>I have a form with several Textboxes that are bound =
to other=20
fields in Table 2 and they work fine.&nbsp; On the same form, I also =
have&nbsp;=20
2 Combo Boxes that are populated with&nbsp;Descriptions from Table 1, =
and the=20
SelectedValue is set according to the value of the Foreign Keys in Table =

2.&nbsp; My problem is at Runtime, both ComboBoxes are set to the same =
value=20
(that of the second Combo box "cmbCLK_OUT_CTP_ID" - or second Data=20
Binding?).</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>Here&nbsp;is my Data Binding =
code:</FONT>&nbsp;</DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV><FONT size=3D2>
<DIV><BR><FONT face=3D"Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; With=20
Me.cmbCLK_IN_CTP_ID</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier =
New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
.DataSource =3D=20
dsLookup.TM_CTP_Clocking_Type<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
.ValueMember =3D "CTP_ID"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
.DisplayMember =3D =
"CTP_DESCRIPTION"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
.SelectedIndex =3D -1</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier =
New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
.DataBindings.Clear()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
.DataBindings.Add(New Binding("SelectedValue", dsEmp,=20
"TM_CLK_Clockings.CLK_IN_CTP_ID"))</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End=20
With</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; With=20
Me.cmbCLK_OUT_CTP_ID</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier =
New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
.DataSource =3D=20
dsLookup.TM_CTP_Clocking_Type<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
.ValueMember =3D "CTP_ID"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
.DisplayMember =3D =
"CTP_DESCRIPTION"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
.SelectedIndex =3D -1</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier =
New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
.DataBindings.Clear()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
.DataBindings.Add(New Binding("SelectedValue", dsEmp,=20
"TM_CLK_Clockings.CLK_OUT_CTP_ID"))</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End=20
With</FONT></FONT></DIV><FONT size=3D2>
<DIV><BR>When I comment out the code for the second ComboBox's Data =
Binding, I=20
get the correct result in the first Combo Box.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Am I doing something wrong in the code or is having 2 relationships =
to the=20
same table too much for .NET Data Binding?</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>Many Thanks,</DIV>
<DIV>Joe</DIV>
<DIV>&nbsp;</DIV>
<DIV>-- <BR><BR>Joe Hanna<BR>Advanced Software=20
Engineering<BR>joe.hanna_AT_advancedsoftware_DOT_net_DOT_au</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0008_01C35525.89B187D0--

Re: Data Binding Issue by Stephen

Stephen
Mon Jul 28 03:12:11 CDT 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" <zorro@msdn.com> wrote in message
news:%231MLDHNVDHA.2252@TK2MSFTNGP10.phx.gbl...
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