For i As Integer = 0 To DataGridView.Rows.Count - 1 << มันทำบรรทัดนี้ครับ
If DataGridView.Rows(i).Selected Then << แล้วก็มาบรรทัดนี้ครับ
MsgBox(DataGridView.Rows(i).Cells(0).Value)
End If << แล้วก็จบบรรทัดนี้ครับ
Next
Option Explicit On
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Public Class Sale_DogList
Private Sub Refresh_Grid()
Dim d_adap As SqlDataAdapter
Dim d_set As DataSet
d_set = New DataSet
d_adap = New SqlDataAdapter("Select Dog_ID,Dog_Name,Dog_Sex,Dog_Color,Dog_Price " & _
" from Kennel_Dog Where Dog_Status = 'SA' ", sqlConnection)
d_adap.Fill(d_set, "Kennel_Dog")
DataGridView.DataSource = d_set.Tables("Kennel_Dog")
DataGridView.Columns("Dog_ID").DisplayIndex = 0
DataGridView.Columns("Dog_Name").DisplayIndex = 1
DataGridView.Columns("Dog_Sex").DisplayIndex = 2
DataGridView.Columns("Dog_Color").DisplayIndex = 3
DataGridView.Columns("Dog_Price").DisplayIndex = 4
DataGridView.Columns("Dog_ID").HeaderText = "รหัสสุนัข"
DataGridView.Columns("Dog_Name").HeaderText = "ชื่อ"
DataGridView.Columns("Dog_Sex").HeaderText = "เพศ"
DataGridView.Columns("Dog_Color").HeaderText = "สี"
DataGridView.Columns("Dog_Price").HeaderText = "ราคา"
DataGridView.Columns("Dog_ID").Width = 70
DataGridView.Columns("Dog_Name").Width = 140
DataGridView.Columns("Dog_Sex").Width = 40
DataGridView.Columns("Dog_Color").Width = 100
DataGridView.Columns("Dog_Price").Width = 90
Private Sub Form13_1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Refresh_Grid()
End Sub
Private Sub bt_Add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_Add.Click
For i As Integer = 0 To DataGridView.Rows.Count - 1
If DataGridView.Rows(i).Selected Then
MsgBox(DataGridView.Rows(i).Cells(0).Value)
End If
Next
End Sub