Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.
btn_addline :
Private Sub btn_addline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_addline.Click
grd_order.RowCount = grd_order.RowCount + 1
End Sub
everything to do with lst_product:
lst_product.DataSource = run_sql_query("SELECT * FROM TBL_PRODUCTS_A154287 ORDER BY FLD_PRODUCT_ID ASC")
lst_product.DisplayMember = "FLD_PRODUCT_ID"
**//This code snippet lets user click on a product id in the list and populates the id and its corresponding price into the column cell**
Private Sub product_list(ByVal pid As String)
Dim getPID As String = "SELECT * FROM TBL_PRODUCTS_A154287 WHERE FLD_PRODUCT_ID='" & pid & "'"
Dim thePTable As New DataTable
Dim reader As New OleDb.OleDbDataAdapter(getPID, myconnection)
reader.Fill(thePTable)
For i As Integer = 0 To grd_order.RowCount - 1
grd_order(0, i).Value = thePTable.Rows(0).Item("FLD_PRODUCT_ID")
grd_order(1, i).Value = thePTable.Rows(0).Item("FLD_PRICE")
Next
End Sub
The btn_addline does work and adds a new row(Row1) to the datagrid the problem is when another row(Row2) is added.
When new row(Row2) is added after btn_addline and a new product id is selected from lst_product the data in Row1 changes along with the selected id. so instead of Row1 : ID0001 | RM12, Row2 : ID0002 | RM45. I get Row1 : ID0002 | RM45, Row2 : ID0002 | RM45
How do i code so that each row/cell is unique?