Salve,
trivialmente dovresti passare la medesima "datasource" alla dgv del form 2, quindi la medesima datatable o dataview... in questo modo le modifiche sono propagate avanti e indietro...
brutalmente, 2 form con 1 datagridview ognuna
form1:
Friend Class Form1
Private m_dt As DataTable = Nothing
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
m_dt = New DataTable("tb1")
For iCol As Integer = 0 To 4
Dim col As DataColumn = New DataColumn With {.ColumnName = String.Format("col{0}", iCol.ToString), .DataType = System.Type.GetType("System.String"), .DefaultValue = "", .MaxLength = 10}
If iCol = 0 Then
m_dt.Columns.Add(New DataColumn With {.AutoIncrement = True, .AutoIncrementSeed = 1, .AutoIncrementStep = 1, .DataType = System.Type.GetType("System.Int32"), .Unique = True})
End If
m_dt.Columns.Add(col)
col = Nothing
Next
For iRow As Integer = 1 To 10
Dim dr As DataRow = m_dt.NewRow
For iCol As Integer = 1 To 5
dr(iCol) = String.Format("{0}:{1}-{2}", iRow.ToString, iCol.ToString, New String(Chr(iCol + 64), iCol))
Next
m_dt.Rows.Add(dr)
dr = Nothing
Next
With DataGridView1
.SuspendLayout()
.DataSource = Nothing
.Columns.Clear()
.AutoGenerateColumns = True
.DataSource = Me.m_dt.DefaultView
.MultiSelect = False
.AllowUserToAddRows = True
.AllowUserToDeleteRows = True
.ResumeLayout()
.Columns(0).ReadOnly = True
End With
End Sub
Private Sub DataGridView1_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
If Not Me.DataGridView1.DataSource Is Nothing AndAlso e.RowIndex >= 0 AndAlso e.ColumnIndex = 0 Then
For Each frm As Form In My.Application.OpenForms
'If frm Is Form2 Then Return ' 1 solo dialogo accessorio
Next
Dim frmDlg As New Form2
With frmDlg
.refDtView = Me.DataGridView1.DataSource
.Show(Me)
End With
End If
End Sub
End Class
form2
Friend Class Form2
Friend Property refDtView As DataView = Nothing
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With DataGridView1
.SuspendLayout()
.DataSource = Nothing
.Columns.Clear()
.AutoGenerateColumns = True
.DataSource = Me.refDtView
.MultiSelect = False
.AllowUserToAddRows = True
.AllowUserToDeleteRows = True
.ResumeLayout()
.Columns(0).ReadOnly = True
End With
End Sub
End Class
con dblclick sul contenuto di una riga in colonna1 si apre form2...
modificando le righe, le modifiche vengono propagate avanti e indietro
questo anche se ci sono diversi form2 aperti (ho remmato 'If frm Is Form2 Then Return ' 1 solo dialogo accessorio in modo da poterne averne diversi) ...
salutoni omnia
--
Andrea