Hi all,
I'm not sure how to explain this better so here goes:
I have an unbounded DataGrid on a form which I partly populate with data from a CSV file. The code below works well enough (I know it's simplistic) but what happens is that once it's done, there's a lot of empty rows at the bottom of the data. My guess is that the sub keeps adding empty rows for some reason until it reaches maximum rows on the DataGrid.
The data in columns 0 and 4 is ignored. Column 0 contains icons and I haven't created those yet, and column 4 contains strings which the application user adds as needed.Code:Private Sub BtPopulate_Click(sender As Object, e As EventArgs) Handles BtPopulate.Click Using AlgoRead As New Microsoft.VisualBasic. FileIO.TextFieldParser( "W:\WaR\Work\Programming\Visual Basic\CoalWorks AIO\CoalWorks AIO\Data\Miners.csv") AlgoRead.TextFieldType = FileIO.FieldType.Delimited AlgoRead.SetDelimiters(",") Dim currentRow As String() Dim CurrentRowCount As Integer = 1 While Not AlgoRead.EndOfData Try currentRow = AlgoRead.ReadFields() DGAlgoWallets.Rows.Add(CurrentRowCount) DGAlgoWallets.Item(2, CurrentRowCount - 1).Value = currentRow(0) DGAlgoWallets.Item(3, CurrentRowCount - 1).Value = currentRow(1) DGAlgoWallets.Item(1, CurrentRowCount - 1).Value = False CurrentRowCount = CurrentRowCount + 1 Catch ex As Microsoft.VisualBasic. FileIO.MalformedLineException MsgBox("Line " & ex.Message & "is not valid and will be skipped.") End Try End While End Using End Sub
Of course, the intended purpose is for the DataGrid to have exactly the amount of rows that there is data for in the file (currently 57 rows). I have no clue as to why it keeps adding many empty rows.




Reply With Quote
