vb.net - VB : How to bind a DataTable to a DataGridView?

标签 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

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 显示到 DataGridViewBerechnung 中:

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

但是我不明白如何填充 DataGridView...

最佳答案

简单地,您可以通过以下方式将您的表作为绑定(bind)源的数据源:

 Me.bindingSourceBerechnung .DataSource = tableTempJDL

稍后,您可以通过以下方式在 datagridview 中绑定(bind)上述绑定(bind)源:

 Me.DataGridViewBerechnung.DataSource = Me.bindingSourceBerechnung 

关于vb.net - VB : How to bind a DataTable to a DataGridView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12141519/

相关文章:

c# - 如何从浏览器调用 WCF 服务 OperationContract?

c# - WPF:创建一个看起来像 Visual Studio 2010 的应用程序

vb.net - 按数字对 datagridview 列进行排序

asp.net - 调试 ASCX 控制

.net - Textbox.text 绑定(bind)到 MySettings 不起作用

vb.net - Excel 自动化插件 - 功能不起作用

c# - DataGridView 没有列

vb.net - 如何使用同一个 Sub 处理多个点击事件

c# - 在 C#/VS 2010 中,如何抑制未标记为编译的文件的错误消息?

c# - BindingSource.Find key 比较不区分大小写?