L'ho usato solo nel mio primo esercizio sui DataGrid. Il modo più semplice che ho trovato per inserire dati in una tabella è quella di utilizzare un popup
Comunque, ripescando il mio vecchio esercizio, ho un pulsante o link che comanda l'inserimento. Nell'evento click ho:
codice:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Me.DataGrid1.EditItemIndex >= 0 Then
Exit Sub
End If
AggiungeRiga()
BindDataGrid()
Dim righe% = Me.DataGrid1.DataKeys.Count
Dim i%
For i = 0 To righe - 1
If Me.DataGrid1.DataKeys(i).ToString = "xxx" Then
Me.DataGrid1.EditItemIndex = i
BindDataGrid()
Exit Sub
End If
Next
End Sub
Private Sub AggiungeRiga()
'Dim valori() As Object = {"xxx", "titolo", "15/3/1955", 1, 10.0}
Dim valori() As Object = {"xxx", DBNull.Value, DBNull.Value, 1, DBNull.Value}
ds.Tables("titles").Rows.Add(valori)
End Sub