DataBinding to a related boolean column, many-to-many relationship
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" p开发者_StackOverflow社区roperty 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?
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!
精彩评论