how to read text from childMdi form textbox?

  • Thread starter Thread starter Adda
  • Start date Start date
A

Adda

If I cycle through the MdiChildActivate event of the
parent form I can read text in a textbox on the child
mdiform --

console.writeline(Me.ActiveMdiChild.Controls(1).Text)

But if I have a sub in the Parent form and reference a
child mdi form like this:

Sub ReadText()
Dim frm As New Form2
console.writeline(frm.txt1.text)
End Sub

--I can't read the text in the textbox of the child form.
How could I read the text in a textbox of a child mdi form
from a sub in the parent form?

TIA
Adda
 
Hi,

Dim frmChild As Form2

For Each frmChild In Me.MdiChildren

Debug.WriteLine(frmChild.TextBox1.Text)

Next



Ken
 
Thank you. I also discovered that if I declare the
childform at the Form level of the Parent form as shared I
can also read the text in the textbox.

While I am at it, what I am actually trying to do is to
refresh a datagrid on the parent form with data that I
enter in the child form. I pass a datarow object to the
child and populate it and then update the dataset with a
dataAdapter (using a button on the childform or an Add
menu selection from the parent form). This works fine but
the new row doesn't show up in the datagrid on the parent
form until after I do a dataset.clear, dataAdatapter.Fill
(dataset, "tbl1") on the parent form from a menu event o
the Parent. Could you suggest a way that I could make the
new row show up in the datagrid when in the same event
that I update the dataset with the data from the childform?

Thank you again for your reply.
Adda
 
Hi,

post your code.

Ken
-----------
Adda said:
Thank you. I also discovered that if I declare the
childform at the Form level of the Parent form as shared I
can also read the text in the textbox.

While I am at it, what I am actually trying to do is to
refresh a datagrid on the parent form with data that I
enter in the child form. I pass a datarow object to the
child and populate it and then update the dataset with a
dataAdapter (using a button on the childform or an Add
menu selection from the parent form). This works fine but
the new row doesn't show up in the datagrid on the parent
form until after I do a dataset.clear, dataAdatapter.Fill
(dataset, "tbl1") on the parent form from a menu event o
the Parent. Could you suggest a way that I could make the
new row show up in the datagrid when in the same event
that I update the dataset with the data from the childform?

Thank you again for your reply.
Adda
 
Sorry, had to step away for a couple of hours. Not at my
desk right now, but the code goes something like the
following:

--in the parent form--------------------

Public Class Parentfrm
Dim ddRow As DataRow
....
Public Property dRow() As DataRow
Get
Return ddRow
End Get
Set(ByVal Value As DataRow)
ddRow = Value
End Set
End Property

Public Sub AddRow()
dataset1.Tables("tbl1").Rows.Add(ddRow)
dataAdapter1.Update(dataset1, "tbl1")
Me.Refresh
'how to refresh datagrid1?
End Sub
....
----------------------------------------------
--in the Child Form---------------------------
....
Private Sub btnAdd(...)...
Dim frm As New Parentfrm
frm.dRow = frm.dataset1.Tables("tbl1").NewRow
frm.dRow(0) = txt0.Text
frm.dRow(1) = txt1.Text
frm.AddRow()
End Sub
-----------------------------------------------

tbl1 resides in a sql Server database. The data is
getting stored correctly. But the new row does not show
up in datagrid1 until I click on a menu event on the
parent form

---------------------------------------------
Private Sub mnuRefresh(...)...
dataset1.clear()
dataAdapter1.Fill(dataset1, "tbl1")
End Sub
-----------------------------------------------

now the new row shows up in datagrid1. I am hoping that I
could accomplish this when I do dataAdapter.Update(...).
If I perform this operation from Parentfrm datagrid1
updates automatically. But if I do it from the childform
it does not.

Any suggestions greatly appreciated on how to get
datagrid1 to update automatically when adding data from
the childform. Thank you very much for your help.

Adda
 
Hi,

Try rebinding the datagrid. Datagrid1.Datasource = ds.tables(0)

Ken
----------
 
I did try that, but still the datagrid on the parent form
did not refresh on dataAdapter.Update call. I also tried
using a separate thread (from the child form). The only
way the datagrid would refresh on the dataAdapter.Update
call is if I added the new data in the parent form
(hardcoded data for now). This is why I was trying to
read the data from the childform to the parent form. I am
sure there is a way to refresh the datagrid from the
childform - just obscure right now.

Any suggestions welcome. And thank you again for all your
replies.

Adda
 
One other interesting thing I noticed if I add new data
from the parent form (which does successfully update and
refresh the datagrid as I desire) is that if I have
multiple childforms loaded, 1) I can only read data from
the forms if I loop through the childforms collection 2)
the data is read from each childform in the order that
each form is opened - like if I have child0, child1,
child2 I will pick up the data in child2 form from the
Parent form and then successfully update the dataset and
successfully refresh the datagrid.

I hope to find a way to refresh the datagrid in the parent
form from the the childform.
 
Hi,

Private Sub btnAdd(...)...
Ken
-----------
Adda said:
One other interesting thing I noticed if I add new data
from the parent form (which does successfully update and
refresh the datagrid as I desire) is that if I have
multiple childforms loaded, 1) I can only read data from
the forms if I loop through the childforms collection 2)
the data is read from each childform in the order that
each form is opened - like if I have child0, child1,
child2 I will pick up the data in child2 form from the
Parent form and then successfully update the dataset and
successfully refresh the datagrid.

I hope to find a way to refresh the datagrid in the parent
form from the the childform.
 
Back
Top