抓取GridView裡的欄位值
LOT.Text = GridView3.Rows(0).Cells(10).TextPrivate SubDataGridView1_CellContentClick(ByVal sender As System.Object, ByVale AsSystem.Windows.Forms.DataGridViewCellEventArgs) HandlesDataGridView1.CellContentClick
'點選單一儲存格
DataGridView1.SelectionMode = DataGridViewSelectionMode.CellSelect
MsgBox("你點選了:" & DataGridView1.CurrentCell.Value.ToString)
Me.DataGridView1.SelectionMode =DataGridViewSelectionMode.FullRowSelect
End Sub
Private SubButton1_Click(ByVal sender As System.Object, ByVale As System.EventArgs) HandlesButton1.Click
'選取整列
'先點一下最左邊儲存格選取整列再按按鍵
Dim I, C, R As Integer
Dim Sel_Count As Integer
Dim S As String
Me.DataGridView1.SelectionMode =DataGridViewSelectionMode.FullRowSelect
Sel_Count =DataGridView1.GetCellCount(DataGridViewElementStates.Selected)
For I = 0 To Sel_Count- 1
C = DataGridView1.SelectedCells(I).ColumnIndex
R = DataGridView1.CurrentRow.Index
DataGridView1.CurrentCell = DataGridView1(C, R)
S = S + DataGridView1.CurrentCell.Value.ToString & vbCrLf
Next
MsgBox("你點選了第" & DataGridView1.CurrentRow.Index & "列" & vbCrLf & S)
EndSub
沒有留言:
張貼留言