Vb.net VB:如何将DataTable绑定到DataGridView?

Vb.net VB:如何将DataTable绑定到DataGridView?,vb.net,visual-studio-2010,datagridview,datatable,Vb.net,Visual Studio 2010,Datagridview,Datatable,我知道这是一个基本的问题,已经被回答了上千次,但我无法让它起作用 我在Visual Studio 2010中工作,在我的Windows应用程序中有两个窗体。在第一个(Main.vb)中,用户输入他的输入并进行计算。在第二个窗口(DataAnalysis.vb)中显示计算结果 在Main.vb中,我创建了包含所有中间计算步骤的临时表: Dim tableTempJDL As DataTable = New DataTable("TempJDL") Dim column As DataColumn

我知道这是一个基本的问题,已经被回答了上千次,但我无法让它起作用

我在Visual Studio 2010中工作,在我的Windows应用程序中有两个窗体。在第一个(Main.vb)中,用户输入他的输入并进行计算。在第二个窗口(DataAnalysis.vb)中显示计算结果

在Main.vb中,我创建了包含所有中间计算步骤的临时表:

Dim tableTempJDL As DataTable = New DataTable("TempJDL")
Dim column As DataColumn

column = New DataColumn("ID", GetType(System.Int32))
tableTempJDL.Columns.Add(column)

column = New DataColumn("PthObjekt", GetType(System.Double))
tableTempJDL.Columns.Add(column)

'further columns are after created using the same method
然后,在DataAnalysis.vb中,我尝试将DataTable
tableTempJDL
显示到
datagridviewberechung

Public bindingSourceBerechnung As New BindingSource()
Me.DataGridViewBerechnung.DataSource = Me.bindingSourceBerechnung

但是我不知道如何填充DataGridView…

简单地说,您可以通过以下方式将表作为bindingsource的数据源:

 Me.bindingSourceBerechnung .DataSource = tableTempJDL
 Me.DataGridViewBerechnung.DataSource = Me.bindingSourceBerechnung 
稍后,您可以通过以下方式在datagridview中绑定上述绑定源:

 Me.bindingSourceBerechnung .DataSource = tableTempJDL
 Me.DataGridViewBerechnung.DataSource = Me.bindingSourceBerechnung 

@TimSchmelter我在问这个问题之前读过这篇文章,但我无法让它起作用。另一个很好的例子是MSDN:。但是这一个使用外部数据库,需要使用连接字符串。它很有效,很好!我只需要在Main.vb中的Sub之外声明tableTempJDL。然后,下面的行开始工作:
Me.bindingSourceBerechnung.DataSource=Main.tableTempJDL
。非常感谢LolCoder!