dim test as new form1

  • Thread starter Thread starter Maarten
  • Start date Start date
M

Maarten

hi all,

i have a settingform(form4)

this form opens from an mdi parent form1
what i want do do is, when i make change in form4 (adjust settings), then a
listview in the mdi parent form1 refreches, this is what i did.

Public Class Form4

Inherits System.Windows.Forms.Form

Dim windowmain As New Form1()

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Next inti

otherwindow.listsetup()

Me.close

End Sub

now the problem is, when i try to open form4 i get an error by all of the
components of

" Object reference not set to an instance of an object."
form1, i think becouse i declare the form as a new form1.

what can i do to comunicate with form1



Regards,

Maarten
 
Maarten,

The simple way is in my opinion that you can work forever from your
me.parentform.mdichildren collection

Something as this in your form4 which is very much changed text in this
message so watch typos
\\\
For Each frm As Form In Me.ParentForm.MdiChildren
If frm.Name = "frm1" Then
DirectCast(frm, form1).Whatever = text.Text
Exit Sub
End If
Next
///
I hope this helps?

Cor
 
thanks for the reply

but i get an error ( syntax error) by "AS" in For Each frm As Form In
Me.ParentForm.MdiChildren.

but i was thinking that it meightbe more simple, if i get the data from the
childform when the parrentform is focussed?

but how wil i do this?
anny suggestions are welcome.

kind regards Maarten.
 
Maarten said:
but i get an error ( syntax error) by "AS" in For Each frm As Form In
Me.ParentForm.MdiChildren.

I assume you are using VB.NET 2002:

\\\
Dim f As Form
For Each f In Me.MdiChildren
...
Next f
///
 
hi,
thanks to reply my quesion.

but it won't work

\\\
Dim f As Form
For Each f In Me.MdiChildren
...
Next f
///

form4 is a childform and has no children
so i think "For Each f In Me.MdiChildren" can't work.(i've writen this code
in form4)

i want to refresh a listview in the parentform(form1) when i press a button
in in the childform.(form4)

regards,
Maarten
 
Maarten,

Are you using VBNet 2002
Than my sample becomes

dim frm as Form
\\\
For Each frm In Me.ParentForm.MdiChildren
If frm.Name = "frm1" Then
DirectCast(frm, form1).Whatever = text.Text
Exit Sub
End If
Next
///

Cor


Cor
 
Maarten said:
i want to refresh a listview in the parentform(form1) when i press a
button in in the childform.(form4)

\\\
DirectCast(Me.MdiParent, MainForm).Button1.Text = "Hello World!"
///
 
Maarten,

I think at least I am confused by this text of you
\\\
this form opens from an mdi parent form1
what i want do do is, when i make change in form4 (adjust settings), then a
listview in the mdi parent form1 refreches, this is what i did.
///

A listview on a MDI parent? How did you do that, is this using panels or
something? A kind of Delphi way form.

Cor
 
indeed a listview on a parrent form in a pannel docked left.

the interface of my program looks like visual studio.net
there are some tools in that listview

regards,
Maarten
 
yes i use vb.net 2002

regards,
Maarten

Cor Ligthert said:
Maarten,

I think at least I am confused by this text of you
\\\
this form opens from an mdi parent form1
what i want do do is, when i make change in form4 (adjust settings), then
a
listview in the mdi parent form1 refreches, this is what i did.
///

A listview on a MDI parent? How did you do that, is this using panels or
something? A kind of Delphi way form.

Cor
 
Maarten said:
i want to refresh a listview in the parentform(form1) when i press a button
in in the childform.(form4)

Take a step back and look at what you have. You basically have some data
(your settings) and you want to show the current state of it in multiple forms.
What that means is that no matter how many other forms are allowed to edit
or change the data, everyone else who is displaying the data needs to be notified
of the change (so they can update their own 'view').

What that amounts to is that you create a class that represents your data
and that can raise events (when the data changes). Any forms that display
your data would get their data from that data class, and they would subscribe
to the events of that class to be notified of any changes. You'd give it properties
to get access to the raw settings, and you'd raise events when the settings change.
You might even implement an interface or two (like IList) to make using the data
a bit easier, but that is not required.

In the 'pattern' culture, you are looking for an Observer pattern, perhaps using
that term in the search engines will help you find simple .Net examples.

HTH
LFS
 
What i do now, is store the data in in a couple of arrays, this is the
datastorage where all my forms get their data.

I think i undertand what you mean with youre last reply, i downloaded an
example code.
but i dont think this wil solve my problem.

I manage to store the data and get it when the program starts, or when i
press a button in the mdi form or when i dragover the listview and more like
this.
but i just can't figure out how to let in this case a listview(in the
parrentform) get's its data by refreshing when i press a button in another
form (a childform) .

i was thinking to set a timer on the refresh property of the listview, but i
don't think this is a propper way to get up to date with data changes in my
program, there must be a more simple way. but how.

the last code you gave me won't work, i get an error "Object reference not
set to an instance of an object."

thanks for the reply's

kind regards Maarten.
 
Maarten,

I did not see that you asked this one
\\\
me.mdiparent.show
///
Not tested by the way

Cor
 
Maarten,

Can you make yourself a little test project

\\\Form1 nothing on it just past in this code
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.IsMdiContainer = True
Dim frm As New Form2
frm.MdiParent = Me
frm.Show()
End Sub
///

\\\Form2 one button and paste in this code
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Me.MdiParent.Text = "blabla"
End Sub
///

Just run click the button than the form name of form1 should change in
"blabla"

I hope this helps,

Cor
 
thank you, indeed this works, now i know what doesn't couses the error.

i'll keep on trying and trying

kind regards,
Maarten
 
this is strange, i did just the same on my project, but is just won't work
do jou have anny idea howcomes??

regards
 
ok i'm realy sorry, but i declared the form as an owned form not as a
childform.
now it works fine.

but how can i call a sub something like

Me.MdiParent.listsetup()

this won't work.

regards Maarten
 
Maarten said:
ok i'm realy sorry, but i declared the form as an owned form not as a
childform.
now it works fine.

but how can i call a sub something like

Me.MdiParent.listsetup()

this won't work.

Would be great if you read my posts...

\\\
DirectCast(Me.MdiParent, MainForm).ListSetup()
///

.... assuming 'MainForm' is the type of your MDI container.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top