小弟遇到了很奇怪的需求,所以DataGrid中显示的内容全部是一行一行手动填充的。现在想把DataGrid的所有数据Copy到新的DataTable中。

解决方案 »

  1.   

    那就手工填充datatable 就可以了!
      

  2.   

    可以從datagrid的數據源dataset等為datatable賦值;可是這樣做有什麽好處呢,同樣的東西顯示兩遍?
      

  3.   

    用循环把datagrid中的值读出来把值传给新建的一个table.
      

  4.   

    相关的技术有:
    datatable.Rows.add方法Private Sub AddARow(ds As DataSet)
        Dim t As DataTable
        t = ds.Tables("Suppliers")
        ' Use the NewRow method to create a DataRow with the table's schema.
        Dim newRow As DataRow = t.NewRow()
        ' Set values in the columns:
        newRow("CompanyID") = "NewCompanyID"
        newRow("CompanyName") = "NewCompanyName"
        ' Add the row to the rows collection.
        t.Rows.Add(newRow)
    End SubPrivate Sub CreateTable()
        Dim IDColumn As New DataColumn("ID")
        IDColumn.DataType = GetType(Integer)
        IDColumn.AutoIncrement = True    Dim FNameColumn As New DataColumn("FirstName")
        FNameColumn.DataType = GetType(String)    Dim LNameColumn As New DataColumn("LastName")
        LNameColumn.DataType = GetType(String)    Dim EmployeeTable As New DataTable("Employees")
        EmployeeTable.Columns.Add(IDColumn)
        EmployeeTable.Columns.Add(FNameColumn)
        EmployeeTable.Columns.Add(LNameColumn)    EmployeeTable.Constraints.Add("Key1", IDColumn, True)
    End Sub