Hello,
I need to populate a DataTable in order to display it with a DataGridView afterwards.
I stored in a variable a string of 670 characters that I have to split into groups of 10 in order to display them in the table, filling it row by row.
So I try to fill the table box by box by going through the number of columns and as soon as we arrive at 10 (the number of columns), we go to the next line, continuing to fill it out from the string which is cut out.
I'm wondering if he best way is it to make a list of string which contains 67 string of 10 characters (the starting string which is split), to create the number of lines starting from the list and to try to fill the array with from that?
![Name: Capture.jpg
Views: 38
Size: 15.4 KB]()
Dim table As New DataTable()
table.Columns.Add("10", Type.GetType("System.String"))
table.Columns.Add("20", Type.GetType("System.String"))
table.Columns.Add("30", Type.GetType("System.String"))
table.Columns.Add("40", Type.GetType("System.String"))
table.Columns.Add("50", Type.GetType("System.String"))
table.Columns.Add("60", Type.GetType("System.String"))
table.Columns.Add("70", Type.GetType("System.String"))
table.Columns.Add("80", Type.GetType("System.String"))
table.Columns.Add("90", Type.GetType("System.String"))
table.Columns.Add("100", Type.GetType("System.String"))
Dim testStr As New List(Of String)
testStr.Add("test1")
testStr.Add("test2")
testStr.Add("test3")
testStr.Add("test4")
testStr.Add("test5")
testStr.Add("test6")
testStr.Add("test7")
testStr.Add("test8")
testStr.Add("test9")
testStr.Add("test10")
testStr.Add("test11")
testStr.Add("test12")
For k = 0 To table.Columns.Count - 1
Dim putNewRow As DataRow = table.NewRow
putNewRow(k) = testStr(k).ToString
table.Rows.Add(putNewRow)
Next
So far I have triedwith the code above, just to try to fill the array as desired but I couldn't.
The goal would be that from "test1" to "test10", we insert on the first line, from "test11" to "test20" on the next, etc ...
Thanks in advance for the help
Last edited by eratail
I need to populate a DataTable in order to display it with a DataGridView afterwards.
I stored in a variable a string of 670 characters that I have to split into groups of 10 in order to display them in the table, filling it row by row.
So I try to fill the table box by box by going through the number of columns and as soon as we arrive at 10 (the number of columns), we go to the next line, continuing to fill it out from the string which is cut out.
I'm wondering if he best way is it to make a list of string which contains 67 string of 10 characters (the starting string which is split), to create the number of lines starting from the list and to try to fill the array with from that?
Dim table As New DataTable()
table.Columns.Add("10", Type.GetType("System.String"))
table.Columns.Add("20", Type.GetType("System.String"))
table.Columns.Add("30", Type.GetType("System.String"))
table.Columns.Add("40", Type.GetType("System.String"))
table.Columns.Add("50", Type.GetType("System.String"))
table.Columns.Add("60", Type.GetType("System.String"))
table.Columns.Add("70", Type.GetType("System.String"))
table.Columns.Add("80", Type.GetType("System.String"))
table.Columns.Add("90", Type.GetType("System.String"))
table.Columns.Add("100", Type.GetType("System.String"))
Dim testStr As New List(Of String)
testStr.Add("test1")
testStr.Add("test2")
testStr.Add("test3")
testStr.Add("test4")
testStr.Add("test5")
testStr.Add("test6")
testStr.Add("test7")
testStr.Add("test8")
testStr.Add("test9")
testStr.Add("test10")
testStr.Add("test11")
testStr.Add("test12")
For k = 0 To table.Columns.Count - 1
Dim putNewRow As DataRow = table.NewRow
putNewRow(k) = testStr(k).ToString
table.Rows.Add(putNewRow)
Next
So far I have triedwith the code above, just to try to fill the array as desired but I couldn't.
The goal would be that from "test1" to "test10", we insert on the first line, from "test11" to "test20" on the next, etc ...
Thanks in advance for the help
Last edited by eratail