Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why is DataGrid control not populating?

Status
Not open for further replies.
Joined
Mar 4, 2001
Messages
43
Location
US
I'm writing an app to parse a device log file and insert the data into a database. As it processes new rows from the device I'd like to simply display them on screen in a datagrid. At first i was trying to build the grid on the fly, but everything seemed to say that it would be easier to build a datatable, so I went that route. Which leads me to:
[tt]
Dim sourceTbl As New DataTable 'Creating DataTable, sourceTbl
sourceTbl.Columns.Add("TblCol1") 'Adding columns to the table
sourceTbl.Columns.Add("TblCol2")
sourceTbl.Columns.Add("TblCol3")
sourceTbl.Columns.Add("TblCol4")
sourceTbl.Columns.Add("TblCol5")
sourceTbl.Columns.Add("TblCol6")
sourceTbl.Columns.Add("TblCol7")
sourceTbl.Columns.Add("TblCol8")
sourceTbl.Columns.Add("TblCol9")
sourceTbl.Columns.Add("TblCol10")
sourceTbl.Columns.Add("TblCol11")
sourceTbl.Columns.Add("TblCol12")
sourceTbl.Columns.Add("TblCol13")
sourceTbl.Columns.Add("TblCol14")

ixx = 1
Dim displayLog = System.IO.File.ReadAllLines("C:\KipLogs\KipLog.csv") 'This reads the combined output file into the displayLog array
For Each iii In displayLog 'And this loop goes through the array line by line
charge = Split(iii, ",") 'charge is an array made from the current line of the logfile being split into chunks
sourceTbl.Rows.Add(charge()) 'Here we should be adding a row to the DataTable sourceTbl
Me.ToolStripStatusLabel1.Text = "Now processing KipLog line " & ixx & " of " & ix
Me.TextBox1.AppendText(iii & vbCrLf) 'Writing the current line of the logfile to the screen for testing purposes
Me.TextBox1.Refresh()
ixx = ixx + 1
Next
[/tt]
First off, I'm getting an error "RankException was unhandled:Attempted to operate on an array with the incorrect number of dimensions." Which I absolutely don't get since the array has 14 members (0-13) and I've obviously got 14 columns. And I've added and removed columns and get the same error.
 
I can't see where you're adding your datatable to a dataset. After populating the dataset, you then set the datasource of the grid.

Code:
Sub AddQryGrid()
        Dim i As Int16, j As Int16
        dsQRY = New DataSet("QRY")
        Tbl = New DataTable("QRY")

        C = New DataColumn("DB")
        C.ColumnName = "DB"
        C.Caption = "DB"
        Tbl.Columns.Add(C)

        C = New DataColumn("Table")
        C.ColumnName = "Table"
        C.Caption = "Table"
        Tbl.Columns.Add(C)


        C = New DataColumn("Field")
        C.ColumnName = "Fields"
        C.Caption = "Fields"
        Tbl.Columns.Add(C)

        C = New DataColumn("Alias")
        C.ColumnName = "Alias"
        C.Caption = "Alias"
        Tbl.Columns.Add(C)

        C = New DataColumn("Sort")
        C.ColumnName = "Sort"
        C.Caption = "Sort"
        Tbl.Columns.Add(C)

        C = New DataColumn("Order")
        C.ColumnName = "Order"
        C.Caption = "Order"
        Tbl.Columns.Add(C)

        C = New DataColumn("Group By")
        C.ColumnName = "Group By"
        C.Caption = "Group By"
        Tbl.Columns.Add(C)

        C = New DataColumn("Criteria")
        C.ColumnName = "Criteria"
        C.Caption = "Criteria"
        Tbl.Columns.Add(C)

        For i = 1 To 3
            C = New DataColumn("Or" & i)
            C.ColumnName = "Or" & i
            C.Caption = "Or..."
            Tbl.Columns.Add(C)
        Next

        [b]dsQRY.Tables.Add(Tbl){/b]
        [b]dgQRY.SetDataBinding(dsQRY, "QRY")[/b]

    End Sub

I hope this helps.



Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Problem resolved. The line that reads:
[tt]sourceTbl.Rows.Add(charge())[/tt]
Should've read:
[tt]sourceTbl.Rows.Add(charge(0), charge(1), charge(2), charge(3), charge(4), charge(5), charge(6), charge(7), charge(8), charge(9), charge(10), charge(11), charge(12), charge(13))[/tt]
I thought you could just pass the array, and there seems like there'd be a way to loop through the interations, but anyway.

Sorry Ron, I should've included that bit of code. After the loop finishes I am already assigning the datatable to the grid as a datasource:
[tt]
Me.LogGrid.DataSource = sourceTbl
Me.ToolStripStatusLabel1.Text = "Done."
[/tt]

Working now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top