Setting Control Data Binding Through the Properties Window

If you select a control such as a TextBox in the Forms designer, and then show the Properties window (using the View menu or the F4 default keyboard shortcut), all of the properties that can be set at design time in the designer are available in that window. There are also a number of pseudo-properties presented in the Properties window that don't correspond one-to-one with individual properties of a control, but that let you generate or modify code through a similar interaction. For example, when you set the (Name) pseudo-property for a control in the Properties window, you aren't actually changing a property on the instance of the class, but changing the name of the instance member variable itself. This is why it is surrounded by parentheses in the Properties window, because it doesn't correspond to a true property on the control instance. Setting the (Name) pseudo-property results in the designer changing every designer-generated line of code using that member variable to reflect the new name. In fact, Visual Studio 2005 goes beyond that and uses its refactoring features to also locate the use of that named instance in all other code in the project and update it there as well.

Likewise, you can set several properties in the Properties window that give you a rich design experience and that also generate more than one line of code in many cases. These properties include the DataSource and DataMember properties for any complex bound control, the Display-Member and ValueMember properties for a lookup bound control like aComboBox or ListBox, and the (DataBindings) set of pseudo-properties for any control. When you select the DataSource, DataMember, Display-Member, or ValueMember properties of a control in the Properties window, a pop-up window that looks like a miniature version of the Data Sources window displays. This window is docked to the property you are setting in the Properties window (see Figure 5.16).

0 0

Post a comment