i've been all over the internet to solve this problem, but i've found no solution to my problem.my concept is this.
Based on selected value within a combo box, the datagridview will populate with values from the database.
For test = 0 To containerdetaildatatable.Rows.Count - 1
DataGridView1.Rows.Add()
DataGridView1.Rows(test).Cells(0).Value = containerdetaildatatable.Rows(test).Item("Roundtrip")
DataGridView1.Rows(test).Cells(1).Value = containerdetaildatatable.Rows(test).Item("NoTrips")
DataGridView1.Rows(test).Cells(2).Value = containerdetaildatatable.Rows(test).Item("Distance")
DataGridView1.Rows(test).Cells(3).Value = containerdetaildatatable.Rows(test).Item("TypeofTrucks")
DataGridView1.Rows(test).Cells(4).Value = containerdetaildatatable.Rows(test).Item("frm")
DataGridView1.Rows(test).Cells(5).Value = containerdetaildatatable.Rows(test).Item("Destination")
Next
but each time i select a value from the combobox, the dgv keeps inserting a blank row. i know it has to do with the .add() part. but how else am i supposed to pass the values. i dont want to bind the data.
now i've tried a 100 ways to remove the blank rows from the dgv once all values are populated, but i keep getting the index out of range error. the latest i tried was
Dim i As Integer = 0
Dim j As Integer = 1
For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells(j).Value IsNot Nothing AndAlso row.Cells(j).Value.ToString() <> "" Then
DataGridView1.Rows.RemoveAt(i)
End If
still it creates the error. can someone provide me with a solution.Thnx