Public Class Form1
Private _dt As DataTable
Private _selectedstrings As New List(Of String)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
_dt = New DataTable
_dt.Columns.Add("Fields")
_dt.Columns.Add("Value")
_dt.Rows.Add("NSN", "XXXXX")
_dt.Rows.Add("AGD", "YYYYY")
_dt.Rows.Add("NASC", "ZZZZZ")
_dt.Rows.Add("FIF", "WWWW")
DataGridView1.DataSource = _dt
DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
End Sub
Private Sub DataGridView1_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If e.RowIndex < 0 Then
Exit Sub
End If
Dim currentcellstring As String = DataGridView1.Rows(e.RowIndex).Cells("Fields").Value.ToString()
If Not _selectedstrings.Contains(currentcellstring) Then
_selectedstrings.Add(currentcellstring)
End If
MsgBox(String.Join(",", _selectedstrings))
End Sub
End Class
ASKER
ASKER
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.
TRUSTED BY
DataGridView1.Rows(0).Cell
The above would get you the value in the first cell in the first row (the collection is zero-based), so if you need to get the 1st and 3rd, based on your grid:
DataGridView1.Rows(0).Cell
DataGridView1.Rows(3).Cell
DataGridView1.Rows(0).Cell
DataGridView1.Rows(3).Cell