Private Sub DataGrid_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid.CurrentCellChanged
If Not IsDBNull(DataGrid.Item(DataGrid.CurrentCell)) Then
tb_orderID.Text = CStr(DataGrid.Item(DataGrid.CurrentCell.RowNumber, 0))
dt_orderDate.Text = CStr(DataGrid.Item(DataGrid.CurrentCell.RowNumber, 1))
If (DataGrid.Item(DataGrid.CurrentCell.RowNumber, 2) = "OR") Then
ordering.Checked = True
Else
received.Checked = True
End If
tb_empFname.Text = CStr(DataGrid.Item(DataGrid.CurrentCell.RowNumber, 4))
tb_partnerName.Text = CStr(DataGrid.Item(DataGrid.CurrentCell.RowNumber, 6))
End If
'=================================================================================================
Dim d_adap As SqlDataAdapter
Dim d_set As DataSet
d_set = New DataSet
d_adap = New SqlDataAdapter("select Order_ID,Vac_ID,Vac_Name,Order_Quantity,Price,Ture_Price " & _
"from Orders, Order_Detail ,Vaccine_Type " & _
"Where Order_ID = Order_No and Vac_ID = Vac_No ", sqlConnection)
d_adap.Fill(d_set, "Order_Detail")
Dim i As Integer = 0
For i = 0 To lv_OrderList.Items.Count - 1
'If lv_OrderList.Items.Count > 1 Then
' lv_OrderList.Items.Clear()
'End If
Next
With lv_OrderList
.Items.Add(i).SubItems(0).Text = d_set.Tables("Order_Detail").Rows(i)("Vac_ID").ToString()
.Items.Add(i).SubItems(0).Text = d_set.Tables("Order_Detail").Rows(i)("Vac_Name").ToString()
.Items.Add(i).SubItems(0).Text = d_set.Tables("Order_Detail").Rows(i)("Price").ToString()
.Items.Add(i).SubItems(0).Text = d_set.Tables("Order_Detail").Rows(i)("Order_Quantity").ToString()
End With
End Sub
อันนี้คือโค๊ดของเรานะ เราเขียนใน even ของ datagridview นะ Code (VB.NET)
If e.RowIndex = DeptDataGridView.Rows.Count - 1 Then
Exit Sub
End If
With DeptDataGridView
ListView1.Items(0).SubItems(0).Text = .Rows.Item(e.RowIndex).Cells(0).Value.ToString()
ListView1.Items(0).SubItems(1).Text = .Rows.Item(e.RowIndex).Cells(1).Value.ToString()
End With
End Sub