R
rlm
This small problem to solve involves a two table database (one parent
and one child table), one winform and two combo boxes.
Combo box A is populated in the Load event. Combo box A pulls data from
the parent table. A second combo box (box B) will be populated (from
the child table) based on data selected in by the user in combo box A.
In the datastore the child contains a numeric foreign key from the
parent.
The goal is to figure out how to display user friendly data in combo
box a and maintain the associated key so that when the user makes a
selection in box a the approriate data is displayed in combo box b
based on the key from the parent.
I believe this is a very common situation.
Microsoft has helped me figure out that the SelectedIndexChanged is the
event where I want to place my code. Note also that I am not looking
for info on how to retrieve data from a database. I have that info.
As an example here is sample data:
Data to display associated key
--------------------- ---------------------
Test 1 1
Test 2 3
Test 4 5
When user selects data in combo box a I need to produce the query
SELECT field1, field2, fieldx FROM childTable WHERE parentKey =
[associated key].
Where do I store the associated key in the combo box? How do I retrieve
the same?
I am looking at the ValueMember property? However, when I attempt to
interrogate the combo box in the dev UI I am seeing "cannot view
indexed property". Morever, I do not see a index on ValueMember.
Thanks in advance.
and one child table), one winform and two combo boxes.
Combo box A is populated in the Load event. Combo box A pulls data from
the parent table. A second combo box (box B) will be populated (from
the child table) based on data selected in by the user in combo box A.
In the datastore the child contains a numeric foreign key from the
parent.
The goal is to figure out how to display user friendly data in combo
box a and maintain the associated key so that when the user makes a
selection in box a the approriate data is displayed in combo box b
based on the key from the parent.
I believe this is a very common situation.
Microsoft has helped me figure out that the SelectedIndexChanged is the
event where I want to place my code. Note also that I am not looking
for info on how to retrieve data from a database. I have that info.
As an example here is sample data:
Data to display associated key
--------------------- ---------------------
Test 1 1
Test 2 3
Test 4 5
When user selects data in combo box a I need to produce the query
SELECT field1, field2, fieldx FROM childTable WHERE parentKey =
[associated key].
Where do I store the associated key in the combo box? How do I retrieve
the same?
I am looking at the ValueMember property? However, when I attempt to
interrogate the combo box in the dev UI I am seeing "cannot view
indexed property". Morever, I do not see a index on ValueMember.
Thanks in advance.