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?