Skip to content

Instantly share code, notes, and snippets.

@ferlyz05
Created December 12, 2013 00:42
Show Gist options
  • Save ferlyz05/7921326 to your computer and use it in GitHub Desktop.
Save ferlyz05/7921326 to your computer and use it in GitHub Desktop.
' Specific Cell Contents to string - (row 0, cell 0)
Dim s As String = Me.DataGridView1.Rows(0).Cells(0).Value
' Selected Cell
Dim s As String = Me.DataGridView1.SelectedCells(0).Value
' A single string containing all selected cell values
Dim s As String = ""
For Each c As DataGridViewCell In Me.DataGridView1.SelectedCells
s = s & c.Value & Environment.NewLine
Next
' A single string for all Cells in a datagridview
Dim s As String = ""
For Each r As DataGridViewRow In Me.DataGridView1.Rows
For Each c As DataGridViewCell In r.Cells
s = s & c.Value & ","
Next
s = s & Environment.NewLine
Next
MsgBox(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment