datagridview不填充单元格中的数据

时间:2012-02-05 21:42:47

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

0 个答案:

没有答案