As discussed in the In Depth section of this chapter, complex data binding allows a control to bind to more than one data element, such as an entire table in a database, at the same time. And as we saw in the In Depth section of this chapter, complex data binding revolves around the DataSource, DataMember, DisplayMember, and ValueMember properties.
Although you often set these properties at design time, you also can set them at run time, as in this example, where I'm binding a dataset to a data grid in code and displaying the authors table:
DataGrid1.DataSource = DataSet11 DataGrid1.DataMember = "authors"
You also can use the built-in data grid method named SetDataBinding for this (data grids are the only controls that have this method):
And here's how to bind the dsDataSet dataset to a list box using the DisplayMember property, using the au_lname field in the authors table, authors.au_lname:
ListBox1.DataSource = dsDataSet ListBox1.DisplayMember = "authors.au_lname"
For more information on complex binding, see the In Depth section of this chapter.