看了MSDN的例子,也没明白。
还有,好像SetDataBinding方法的参数必须要有DataSet,只有DataTable不行。

解决方案 »

  1.   

    和“运行时”相对的概念是“设计时”设计时:是指在IDE环境中ing...;
    运行时:是指双击后,程序在运行中ing...;
      

  2.   

    请大家结合MSDN的例子,说一下DataGrid设置数据源,何时使用DataSource、DataMember属性,何时使用SetDataBinding方法?DataSource、DataMember的例子:
    private void BindToDataView(DataGrid myGrid){
        // Create a DataView using the DataTable.
        DataTable myTable = new DataTable("Suppliers");
        // Insert code to create and populate columns.
        DataView myDataView = new DataView(myTable);
        myGrid.DataSource = myDataView;
     }
     private void BindToDataSet(DataGrid myGrid){
        // Create a DataSet.
        DataSet myDataSet = new DataSet("myDataSet");
        // Insert code to populate DataSet with several tables.
        myGrid.DataSource = myDataSet;
        // Use the DataMember property to specify the DataTable.
        myGrid.DataMember = "Suppliers";
     }
     private DataView GetDataViewFromDataSource(){
        // Create a DataTable variable, and set it to the DataSource.
        DataView myDataView;
        myDataView = (DataView) dataGrid1.DataSource;
        return myDataView;
     }
     private DataSet GetDataSetFromDataSource(){
        // Create a DataSet variable, and set it to the DataSource.
        DataSet myDataSet;
        myDataSet = (DataSet) dataGrid1.DataSource;
        return myDataSet;
     }
    SetDataBinding方法的例子:
    private void BindControls(){
        // Creates a DataSet named SuppliersProducts.
        DataSet SuppliersProducts = new DataSet("SuppliersProducts");
        // Adds two DataTable objects, Suppliers and Products.
        SuppliersProducts.Tables.Add(new DataTable("Suppliers"));
        SuppliersProducts.Tables.Add(new DataTable("Products"));
        // Insert code to add DataColumn objects.
        // Insert code to fill tables with columns and data.
        // Binds the DataGrid to the DataSet, displaying the Suppliers table.
        dataGrid1.SetDataBinding(SuppliersProducts, "Suppliers");
     }
      

  3.   

    你的datagrid要承载的数据集就是datasource,一个dataset(datasource)可能有多个表组成,要让datagrid显示哪张表的数据,那么这个表就是你的DataMember
      

  4.   

    dlzhangln:有分,你说得我都知道,我的问题是:
    DataGrid设置数据源,何时使用DataSource、DataMember属性,何时使用SetDataBinding方法?
      

  5.   

    学习一下,没用过SetDataBinding方法