views:

36

answers:

1

This is a WinForms application.

There is a many-to-many relationship between the rows in TABLEA and TABLEB. There is a record in TABLELINK for every row in TABLEA that is related to a row in TABLEB. Think "users" and "roles" or something similar, with each TABLELINK record indicating "user X has role Y."

I'm browsing through TABLEA records using databinding objects. No problem. This is not a grid, just a form with individual TextBox controls.

I want to display a group of checkboxes, each corresponding to a row in TABLEB. I want to bind the TABLELINK data to the "checked" property of each checkbox, so box Y is checked when we are looking at a record X if and only if there is a TABLELINK record matching that X and Y.

I'm having a heck of a time creating this relation and binding it to the checkboxes, which have to be created at runtime because the designer doesn't know how many there will be. Conceptually, in SQL this is select count(*) from tableb left join tablelink on tableb.y = tablelink.y where tablelink.x = ? group by tableb.y but I'm stuck on how to bind this to the individual checkboxes.

My two-part question is: a) Am I architecting this in good way to begin with? b) If so, how do I bind the results of this query (or a similar one) to the individual checkboxes?

+1  A: 

Not sure about a) - I have always wondered myself if I am doing this right.

What i have done is grab a dataset - and render a grid of the names (based on table 1 in the dataset) then render a checkbox list based on query of the dataset (table 2 in the dataset) and if its checked of not based on data in the second part

Not sure its the answer that you wanted but it works!

codemypantsoff
Thanks for your answer. The application doesn't call for a grid, and this is WinForms so I don't have a CheckBoxList, but I wonder if I can set up a query adapter for those checkboxes anyway.I think a big issue with the whole databinding concept is that Microsoft tends to document it in generalities. I don't see much that says "If you do this, you will get that." Very vague.
catfood