VB:如何将DataTable绑定到DataGridView? [英] VB: How to bind a DataTable to a DataGridView?

查看:608
本文介绍了VB:如何将DataTable绑定到DataGridView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个基本的问题,已经被回答了一千次,但是我无法使其工作。



我正在Visual Studio 2010和在我的Windows应用程序中有两种形式。在第一个(Main.vb)中,用户输入他的输入并进行计算。在第二个(DataAnalysis.vb)中,显示计算结果。



在Main.vb中,创建将包含所有中介计算步骤的临时表: / p>

  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 Double))
tableTempJDL.Columns.Add(column)

'使用相同方法创建后的列

然后,在DataAnalysis.vb中,我尝试将DataTable tableTempJDL 显示在 DataGridViewBerechnung

 公共bindingSourceBerechnung作为新的BindingSource()
Me.DataGridViewBerechnung.DataSource = Me.bindingSourceBerechnung

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

解决方案

简单来说,您可以按照以下方式将您的表格作为bindingsource的数据源:

  Me.bindingSourceBerechnung .DataSource = tableTempJDL 

之后,你可以通过以下方式绑定datagridview中的绑定源:

  Me.DataGridViewBerechnung.DataSource = Me.bindingSourceBerechnung 


I know this is a basic question that has already been answered thousand times, but I can't make it work.

I am working in Visual Studio 2010 and have two forms in my Windows Application. In the first one (Main.vb), the user enters his inputs and the calculation takes place. In the second one (DataAnalysis.vb) the calculation results are displayed.

In Main.vb, I create the temp table that will contains all the intermediary calculation steps:

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

Then, in DataAnalysis.vb, I try to display the DataTable tableTempJDL into the DataGridViewBerechnung:

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

But then I don't understand how to fill the DataGridView...

解决方案

Simply, you can make your table as the datasource of bindingsource in following way:

 Me.bindingSourceBerechnung .DataSource = tableTempJDL

Later on, you can bind above binding source in your datagridview in following way:

 Me.DataGridViewBerechnung.DataSource = Me.bindingSourceBerechnung 

这篇关于VB:如何将DataTable绑定到DataGridView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆