Legge il contenuto di una DataGrid





Private Sub ScriviCampiTabella()
Dim rowNumber As Integer = 1
Dim I As Integer
' conta quante righe ci sono

For Each row As DataGridViewRow In DataGridView1.Rows
If row.IsNewRow Then Continue For
'row.HeaderCell.Value = "Row " & rowNumber

rowNumber = rowNumber + 1
Next
' visualizza il contenuto di ogni colonna (campo)per ogni riga

Dim Righe As Long
Dim Stringa As String = ""
For Righe = 0 To rowNumber - 1
For I = 0 To DataGridView1.ColumnCount - 1

'PrintLine(1, "Campo Tabella " & DataGridView1.Columns(I).Name)

Try


'Campo Tabella ColumnName

If DataGridView1.Columns(I).Name = "ColumnName" Then
Stringa = Stringa & DataGridView1.Rows(Righe).Cells(I).Value.ToString & vbTab
'Campo Tabella ColumnSize

ElseIf DataGridView1.Columns(I).Name = "ColumnSize" Then
Stringa = Stringa & DataGridView1.Rows(Righe).Cells(I).Value.ToString & vbTab
'Campo Tabella IsKey

ElseIf DataGridView1.Columns(I).Name = "IsKey" Then
Stringa = Stringa & DataGridView1.Rows(Righe).Cells(I).Value.ToString & vbTab
'Campo Tabella DataType

ElseIf DataGridView1.Columns(I).Name = "DataType" Then
Stringa = Stringa & DataGridView1.Rows(Righe).Cells(I).Value.ToString & vbTab
'Campo Tabella ProviderType

ElseIf DataGridView1.Columns(I).Name = "ProviderType" Then
Stringa = Stringa & DataGridView1.Rows(Righe).Cells(I).Value.ToString & vbTab
End If

'Debug.Print("Campo Tabella " & DataGridView1.Columns(I).Name & " - Valore " & DataGridView1.Rows(Righe).Cells(I).Value.ToString)

Catch ex As Exception

End Try


Next I
PrintLine(1, " " & Stringa)
Stringa = ""

Next Righe
End Sub










( leggeilcontenutodiunadatagrid.html )- by Paolo Puglisi - Modifica del 17/12/2023