Update MDI Child DatagridView from another MDI Child

  • Thread starter Thread starter Coderv9
  • Start date Start date
C

Coderv9

Guest
Hi,

I have 3 forms, Form1 = MDI parent, Form2 = Input Form (MDI Child), Form3 = Datagrid form (MDI Child)

While trying to update data from form2 to form3 we get error but the same works if form2 and form3 are not a MDI Child.

Please help.

1493062.jpg


And below is the code:


MDI Parent:


Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim f As New Form2
f.MdiParent = Me
f.Show()

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim f As New Form3
f.MdiParent = Me
f.Show()
End Sub
End Class


Child Form 1:

Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
With Form3
Dim row As String() = New String() {"Test1", "Test2", "Test3"}
.ReceiveValue(row)
End With
End Sub
End Class


Child Form 2:

Public Class Form3
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
dg_chat.ColumnCount = 3
dg_chat.Columns(0).Name = "Column1"
dg_chat.Columns(1).Name = "Column2"
dg_chat.Columns(2).Name = "Column3"
End Sub

Public Sub ReceiveValue(row As String())
dg_chat.Rows.Add(row)
Me.Activate()
Me.Refresh()
End Sub
End Class


And this is the error while trying to update the data from Form2 to form3.

{"No row can be added to a DataGridView control that does not have columns. Columns must be added first."}


Coderv9

Continue reading...
 
Back
Top