|
-
Nov 29th, 2010, 08:25 PM
#1
Thread Starter
New Member
[RESOLVED] Populating a Datafield Grid
Hey, I'm trying to bring a text file that is tab delimited so i can preform calculations on it. This is in Visual Studio 2010
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim filename As String = "I:\Test.txt"
Dim dtTest As New DataTable("dtTest")
dtTest.Columns.Add("Col1", GetType(String)) 'this displays the data correctly
Try
Dim reader As New Microsoft.VisualBasic.FileIO.TextFieldParser(filename)
reader.TextFieldType = FileIO.FieldType.Delimited
reader.SetDelimiters(" ")
While Not reader.EndOfData
Dim Fields() As String = reader.ReadFields
dtTest.Rows.Add(Fields)
End While
reader.Close()
Catch ex As Exception
MessageBox.Show(Err.Description)
End Try
DataGridView1.DataSource = dtTest.DefaultView
End Sub
This code works in populating my data grid but it puts all of columns on my text file into one column. I realize i only added one column within my code but I'm not sure how to make breaks or skips when it reads the text file. I want to have all of column one in column one of the data table and then all of column two of my text file in the datatable. What can I can I change to make this possible so all of my columns and rows aren't in 1 single column of my datagridview?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|