cargar fichero csv en datagridview
Publicado por SELMA (1 intervención) el 23/03/2007 12:37:21
Hola a todos! mi problema es que necesito leer un fichero .csv y que me cargue cada dato en una celda de un datagridview. Con el código que adjunto consigo leerlo pero lo que hace es escribirme el último valor leido en todas las celdas. ¿Me podeis ayudar para conseguir que escriba un valro en cada celda?
Gracias!
Using lector As New Microsoft.VisualBasic.FileIO.TextFieldParser(fichero)
lector.TextFieldType = FileIO.FieldType.Delimited
lector.SetDelimiters(",")
Dim fila As String()
While Not lector.EndOfData
'Try
fila = lector.ReadFields()
Dim dato As Object
For Each dato In fila
For i = 0 To 23
DataGridView2.Item(1 + i, 0).Value = dato
Next
Next dato
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & "is not valid and will be skipped.")
End Try
End While
End Using
Gracias!
Using lector As New Microsoft.VisualBasic.FileIO.TextFieldParser(fichero)
lector.TextFieldType = FileIO.FieldType.Delimited
lector.SetDelimiters(",")
Dim fila As String()
While Not lector.EndOfData
'Try
fila = lector.ReadFields()
Dim dato As Object
For Each dato In fila
For i = 0 To 23
DataGridView2.Item(1 + i, 0).Value = dato
Next
Next dato
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & "is not valid and will be skipped.")
End Try
End While
End Using
Valora esta pregunta


0