Hello all,
I have been looking all over the net for a good easy example to achieve the above. I'm a beginner in programming, so please make it as simple as possible. I'm working with Visual Basic 2010.
I have a text file in this format:
0110000105c179a7 _____,.__
0110000105b4f67a (( *
011000010597d255 _-StraNn1K-_
0110000103f169d4 ..
0110000105b8a73f [GER]Skilljump
No headings... The data on the left has a fixed length of 16 alphanumeric characters, the right side variable the columns are separated by a single space. I would like to read the file into a datagrid so that the user can look through it and add and/or delete lines as needed then re-save the text file in the same format. It needs to be this way because the file belongs to another program and that is what they use, I merely want to automate the process of working witht the file and avoid having to manipulate a text file by hand (notepad/wordpad, etc).
I have tried the following code:
Dim lines() As String = IO.File.ReadAllLines("C:\permanent.ban")
Dim dt As New DataTable
For x As Integer = 1 To lines(0).Split(CChar(vbTab)).Length
dt.Columns.Add("Column" & x.ToString)
Next
For x As Integer = 0 To lines.GetUpperBound(0)
Dim dr As DataRow = dt.NewRow
dr.ItemArray = lines(x).Split(CChar(vbTab))
dt.Rows.Add(dr)
Next
DataGridView1.DataSource = dt
It somewhat works, but this produces the datagridview with all the data in one column and also creates a blank row after each record. I have tried to add:
dt.Columns.Add("Column2" & x.ToString)
But all it does is add a second column with a heading of "Column21" fo some strange reason.
Any help you can provide would be GREATLY appreciated.
Thanks again,
WarriorII