0

私はこのデータグリッドビューを持っています:

ここに画像の説明を入力してください

ここで、最初の行がダブルクリックされたときに、すべてのデータを変数に保存する必要があります。たとえば、フィールドは変数名で、別nameの変数名でname入力する必要があります。First Namefname

DataGridView1.CellContentDoubleClick呼び出されたプロパティを使用してeventを使用して値を取得しようとしていますSelectedCellsが、インテリセンスは、特定の選択された行の各列の値を取得する方法に関する情報を提供していません。

4

2 に答える 2

4

datagridview から直接データを取得するには、次のようにします。

Dim fName As String = String.Empty
Dim sName As String = String.Empty

Private Sub DataGridView1_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentDoubleClick
    If DataGridView1.SelectedRows.Count <> 0 Then
        Dim row As DataGridViewRow = DataGridView1.SelectedRows(0)
        fName = row.Cells("fNameColumnName").Value
        sName = row.Cells("sNameColumnName").Value
    End If
End Sub

ただし、これは multiselect プロパティが true に設定されていると機能しません。

于 2012-08-23T13:57:15.850 に答える
1

最後に、答えが得られたので、ここで共有します。

Private Sub DataGridView1_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentDoubleClick
        frm_dashboard.lbl_pnum_text.Text = DataGridView1.SelectedRows(0).Cells(0).Value
        frm_dashboard.lbl_pname_text.Text = DataGridView1.SelectedRows(0).Cells(2).Value + " " + DataGridView1.SelectedRows(0).Cells(1).Value
        frm_dashboard.lbl_paddress_text.Text = DataGridView1.SelectedRows(0).Cells(4).Value
        frm_dashboard.Enabled = True
        Me.Hide()
    End Sub
于 2012-08-24T06:01:08.187 に答える