0

I have built a combo box that uses a dataset with 2 tables, in order to perform a lookup for the values to display, but save a different value back.

It was built from this great blog (her first item of the two in the bog): http://blogs.msdn.com/b/bethmassi/archive/2007/04/25/tips-on-related-data-binding-and-comboboxes.aspx

Now I have one more step to take which I'm hoping someone can help with:

In my case, the combobox is filling in a 'parent Id'. So it's helping to build a parent-child hierarchy in the table. (think of the table as being 3 columns - Id, Name, ParentId) So the dataset has two tables, and in fact they are the same database table, related by a parent id.

This works great - but I'd like to clean it up just a bit more: The combobox should not display the child's name in the list. Ie. it should show all other possible choices, but it shouldn't let the user select the child as it's own parent.

Should I use some sort of filter query that refers to the bindingsource's Id of the child? Should I alter the select statement in the dataset for the combobox and maybe use a parameter to obtain the child's id to filter? I'm not sure how to approach it.

Let me know if it's unclear Thanks!

da Bich
  • 494
  • 1
  • 4
  • 13

1 Answers1

0

i went with altering the select query for the parent's tableadapter, and passed the current child as a parameter to the Fill.

works nice!

(the added clause to the parent select was something like: (Id <> @curId) AND (Id NOT IN (SELECT Id FROM table AS table_1 WHERE (ParentID = @curId)))

->the second part was added so that they also couldn't have one of their own children as their parent.

da Bich
  • 494
  • 1
  • 4
  • 13