TreeView for WinForms
DataSetの連結
データ連結 > DataSetの連結

Just like binding with relational lists, TreeView can be bound to relational datasets, where relationships are defined between individual tables. The TreeView control can automatically generate the KeyField and ParentKeyField properties from the relations in the dataset. This also helps in displaying the tables hierarchically by setting the DataSource and DataMemberPath properties of BindingInfo class.

The image below depicts dataset binding in the TreeView control.

TreeView UI

To bind TreeView to a DataSet, follow these steps:

  1. Set the datasource for TreeView using the DataSource property. Note that here we fetch the data from the DataSet class using the GetData method. You can find the code for DataSet class here.
    C#
    コードのコピー
    Type your example code here. It will be automatically colorized when you switch to Preview or build the help system.
    
  2. Set the data members for tree levels.
    C#
    コードのコピー
    Type your example code here. It will be automatically colorized when you switch to Preview or build the help system.
    
  3. Configure and add the columns to be displayed in the TreeView. Set the DisplayFieldName property to get the list of fields to be displayed in the columns and the DisplayMemberPath property to get a collection that identifies the fields to be displayed in a column depending on the node level.
    C#
    コードのコピー
    Type your example code here. It will be automatically colorized when you switch to Preview or build the help system.