I have a winforms application with a bunch of controls that are visually arranged in a hierarchical/level structure.
The point of the application is that it holds information for different “levels” of something. Let’s look at an employee records example.
As you can see each employee is positioned below and/or above another. Each employee has a few labels and a PictureBox control associated with them.
I have a database that will hold all the information about the content of the labels (i.e. their “Text” property) and the PictureBoxes (i.e. their “Image” property).
The question is: “How do I make them automatically set their own content?”.
I don’t want to hardcode anything and the best I could come up with was, basically, “get the information from the DB for all employees, then for each employee find a label that has something in its “Name” property that ties it to said employee and set its “Text” property appropriately.” (since I have named the controls in a way which identifies which “level” of employee they belong to.
But I don’t quite like that method. I was thinking I could go with “Tag” properties but wondered if there isn’t some trick/pattern/whatever that would be the best approach to “Hey, control – based on ‘something’ get the data that you are supposed to display!”.