Vb.net datagridview未在单元格中填充数据

Vb.net datagridview未在单元格中填充数据,vb.net,datagridview,Vb.net,Datagridview,我正在表单加载上构建datagridview。代码生成所需的值,但结果是网格添加了适当数量的行,但数据永远不会显示在单元格中。代码如下 Private Sub frmADRORD_Load(sender As Object, e As System.EventArgs) Handles Me.Load ' Fill in the data grid with a List ' Get a DataTable instance from helper function. D

我正在表单加载上构建datagridview。代码生成所需的值,但结果是网格添加了适当数量的行,但数据永远不会显示在单元格中。代码如下

Private Sub frmADRORD_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    ' Fill in the data grid with a List
    ' Get a DataTable instance from helper function.
    Dim dt As New DataTable
    dt = GetTable()
    'BindingSource1.DataSource = dt
    datagridADRORD.DataSource = dt
End Sub

''' Helper function that creates new DataTable.
''' </summary>
Function GetTable() As DataTable
    ' Create new DataTable instance.
    Dim table As New DataTable
    ' Create four typed columns in the DataTable.
    table.Columns.Add("ADR Symbol", GetType(String))
    table.Columns.Add("ADR Price", GetType(Double))
    table.Columns.Add("ORD Symbol", GetType(String))
    table.Columns.Add("ORD Price", GetType(Double))
    table.Columns.Add("Ratio", GetType(Double))
    table.Columns.Add("Currency", GetType(String))
    table.Columns.Add("Currency Price", GetType(Double))
    table.Columns.Add("Difference", GetType(Double))
    table.Columns.Add("GoNoGo", GetType(String))

    'start to loop thru all the symbols in the symbols file
    ' first read them into an array
    'the line below is for the commodity symbols file 
    Dim strText As String = File.ReadAllText("F:\ADR-ORD Program\ADR-ORD Comparator\ADR-ORD Comparator\SymbolsinBBRGFormat.txt")
    Dim aryText() As String = strText.Split(";")
    strText = vbNullString
    Dim x As Integer
    Dim symADR As String = "", symORD As String = 0, strCurncy As String = ""
    Dim dblADRPx As Double = 0, dblORDPx As Double = 0, dblCurncyPx As Double = 0
    Dim ratio As Double = 1, diff As Double = 0, goNogo As String = ""


    For x = 0 To UBound(aryText) - 1
        Dim newADRrow As DataRow = table.NewRow()

        newADRrow("ADR Symbol") = Split(aryText(x), ",")(0)
        newADRrow("ADR Price") = 1 'add bbrg formula here?
        newADRrow("ORD Symbol") = Split(aryText(x), ",")(1)
        newADRrow("ORD Price") = 1 ' add bbrg formula here?
        newADRrow("Ratio") = Split(aryText(x), ",")(2)
        newADRrow("Currency") = Split(aryText(x), ",")(3)
        newADRrow("Currency Price") = 1
        newADRrow("Difference") = 1
        newADRrow("GoNoGo") = "Go"
        MsgBox(newADRrow.ToString())
        ' Add rows of data for those columns filled in the DataTable.
        table.Rows.Add(newADRrow)

    Next x
    Return table
End Function
Private Sub frmADRORD\u Load(发送方作为对象,e作为System.EventArgs)处理Me.Load
'用列表填充数据网格
'从helper函数获取DataTable实例。
Dim dt作为新数据表
dt=GetTable()
'BindingSource1.DataSource=dt
datagridADRORD.DataSource=dt
端接头
''创建新数据表的帮助函数。
''' 
函数GetTable()作为DataTable
'创建新的DataTable实例。
Dim表作为新数据表
'在DataTable中创建四个类型化列。
table.Columns.Add(“ADR符号”,GetType(字符串))
表.Columns.Add(“ADR价格”,GetType(双精度))
table.Columns.Add(“ORD符号”,GetType(字符串))
表.列.添加(“ORD价格”,GetType(双精度))
table.Columns.Add(“比率”,GetType(双精度))
table.Columns.Add(“货币”,GetType(字符串))
table.Columns.Add(“货币价格”,GetType(Double))
table.Columns.Add(“差异”,GetType(双精度))
table.Columns.Add(“GoNoGo”,GetType(String))
'开始循环遍历符号文件中的所有符号
'首先将它们读入数组
'下一行用于商品符号文件
Dim strText As String=File.ReadAllText(“F:\ADR-ORD程序\ADR-ORD比较器\ADR-ORD比较器\SYMBOLSINBRGFORMAT.txt”)
Dim aryText()作为字符串=strText.Split(“;”)
strText=vbNullString
作为整数的Dim x
Dim symADR As String=“”,symORD As String=0,STRURNCY As String=“”
Dim dblADRPx为Double=0,dblORDPx为Double=0,dblCurncyPx为Double=0
Dim ratio为Double=1,diff为Double=0,goNogo为String=“”
对于x=0到UBound(aryText)-1
Dim newADRrow As DataRow=table.NewRow()
NEWADROW(“ADR符号”)=拆分(文本(x),“,”)(0)
newADRrow(“ADR价格”)=1'是否在此添加bbrg公式?
NEWADROW(“ORD符号”)=拆分文本(x),“,”)(1)
newADRrow(“ORD价格”)=1'在此处添加bbrg公式?
newADRrow(“比率”)=拆分文本(x),“,”)(2)
newADRrow(“货币”)=拆分文本(x),“,”)(3)
newADRrow(“货币价格”)=1
newADRrow(“差异”)=1
newADRrow(“GoNoGo”)=“开始”
MsgBox(newADRrow.ToString())
'为数据表中填充的列添加数据行。
table.Rows.Add(newADRrow)
下一个x
返回表
端函数

是否尝试将BindingSource的数据源设置为DataTable,将DataGridView的数据源设置为BindingSource?是的,正如您在表单加载中看到的,它被注释掉了…它具有相同的结果。我只能看到您已经将它的数据源设置为DataTable,并不是说您已经将DataGridView的数据源设置为BindingSource。load“BindingSource1.DataSource=dt DataGridAdrod.DataSource=dt”表单中的这段代码片段是这样尝试的,smae结果如上所述“BindingSource1.DataSource=dt DataGridAdrod.DataSource=BindingSource1Yes,我一开始就已经看到了,但只有评论指出您试图设置BindingSource的数据源。