JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Binding Data Grids

As we've already seen, you can use data grids to display entire data tables, as in the DataBinding example on the CD-ROM, as discussed in the In Depth section of this chapter. To bind a data grid to a table, you can set the data grid's DataSource property (usually to a dataset, such as dsDataSet) and DataMember property (usually to text naming a table like "authors"). At run time, you can set both of these properties at once with the built-in data grid method SetDataBinding (data grids are the only controls that have this method):

DataGrid1.SetDataBinding(dsDataSet, "authors")

You can use these data sources with the data grid's DataSource property:

  • DataTable objects

  • DataView objects

  • DataSet objects

  • DataViewManager objects

  • single dimension arrays

To determine which cell was selected by the user, use the CurrentCell property. You can change the value of any cell using the Item property, which can take either the row or column indexes of the cell. And you can use the CurrentCell Changed event to determine when the user selects another cell.

You can see an example of data binding with this control in the DataBinding example on the CD-ROM in Figure 21.3, where I've bound the data grid to the authors table in the pubs database.

Previous Section Next Section




JavaScript Editor Free JavaScript Editor     JavaScript Editor