|
分類:[VB.NET]
選択されたセルのうち、一番最初を扱うんであればこんな感じでしょうか。
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Me.DataGridView1.Columns.Add("Field1", "Field1") Me.DataGridView1.Columns.Add("Field2", "Field2") Me.DataGridView1.Columns.Add("Field3", "Field3") Me.DataGridView1.Rows.Add("nakanonaka", "jeannne", "jitta") Me.DataGridView1.Rows.Add("tocchann", "mnow", "o??") End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Me.DataGridView1.SelectedCells.Count < 1 Then Return Dim selectedValue As Object = Me.DataGridView1.SelectedCells(0).Value If IsDBNull(selectedValue) Then Return Dim strSelectedValue As String = selectedValue.ToString() MessageBox.Show(strSelectedValue + "が選択されてますね") End Sub End Class
|