Add information to datagridview (VB.NET)
Ok I change my question...
I have two split-arrays and two columns (first name and last name). How can I add my two split-arrays to my datagridview?
My code does not work, because all last name entries are at first name.
For k = 0 To UBound(array1)
datagradview.Rows.Add(array1(k))
For i = 0 To UBound(array2)
datagradview.Rows.Add(array2(i))
Next (i)
Next (k)
开发者_运维问答
I would use a different approach other than UBound firstly, try to use "Count" or Length where possible so you don't end up with top heavy arrays.
If you have two one-dimensional arrays (which are of the same length) then define the columns in a new DataTable as they should be displayed in your DGV and then use your DGV.DataSource = your new DataTable:
Dim resultsDT as New DataTable
resultsDT.Columns.Add("FirstName", GetType(System.String))
resultsDT.Columns.Add("LastName", GetType(System.String))
Dim k as Int16
For k = 0 to array1.Length - 1
resultsDT.Rows.Add(array1(k), array2(k))
Next k
DataGridView_Results.DataSource = resultsDT
I hope this helps
精彩评论