473,389 Members | 1,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,389 software developers and data experts.

Read data between parent and child form

I have a ListBox on the main form, in the child form when accessing items I
get an error message "Object reference not set to an instance of an object."
here is the code in the child form. Is there something I am missing i.e.
setting the reference to the main form to access ListBox items?

Public Class frmWinZipExecution
Inherits System.Windows.Forms.Form

Public MainForm As frmMainForm ' For accessing calling form

....

Private Sub cmdBuild_Click(ByVal sender As System.Object,....
Dim iFileCount As Integer
Dim iFile As Integer

Try
iFileCount = MainForm.ListBox1.Items.Count
For iFile = 1 To iFileCount - 1
Debug.WriteLine(MainForm.ListBox1.GetItemText(iFil e))
Next
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Sub
Thanks for any help you can provide,
Kevin
Nov 21 '05 #1
5 1726
Kevin,

This instruction
\\\
Public MainForm As frmMainForm ' For accessing calling form
///

This tells that MainForm is from the type (format) frmMainForm, it is not
even instanced.

What are you up to, because probably your problem is easier to tackle like
this (I find it not nice, however when you want it).

In your mainform
\\\
dim frm as new SecondForm
frm.mylistbox = me.listbox
frm.showdialog
///
And than in the other form
\\\
public mylistbox as listbox
////

I hope this helps

Cor
Nov 21 '05 #2
Cor,

Yes I understand what you are saying. Usually as I code questions like the
one asked here help me to better understand how things run in WinForms. So I
am still looking how to properly access the main form from the current child
form.

Thanks for you assistance,
Kevin

"Cor Ligthert" <no************@planet.nl> wrote in message
news:O6**************@TK2MSFTNGP09.phx.gbl...
Kevin,

This instruction
\\\
Public MainForm As frmMainForm ' For accessing calling form
///

This tells that MainForm is from the type (format) frmMainForm, it is not
even instanced.

What are you up to, because probably your problem is easier to tackle like
this (I find it not nice, however when you want it).

In your mainform
\\\
dim frm as new SecondForm
frm.mylistbox = me.listbox
frm.showdialog
///
And than in the other form
\\\
public mylistbox as listbox
////

I hope this helps

Cor

Nov 21 '05 #3
Found the solution I was hunting for;
In the main form

Dim f As New frmWinZipExecution
Try
f.MainForm = Me
f.ShowDialog(Me)
Finally
f.Dispose()
End Try
In the child form

#Region "Access Main Form Code"
Public Property MainForm() As frmMainForm
Get
Return mMainForm
End Get
Set(ByVal Value As frmMainForm)
mMainForm = Value
End Set
End Property
#End Region

....

Me.MainForm.ListBox1.Items.Add("Added from Child form")
Guess I would ask if there are any problems with this code.
Credit for above code can be found at
http://www.dotnetsmart.com/forums/993/ShowPost.aspx
Nov 21 '05 #4
Kevin,

It is the same as the code I showed in a different way.

What you do is passing the reference of that listbox.

Now I know you use that showdialog, than it is easier (and better as well as
my first sample) to do it in this way.

\\\
f.ShowDialog(Me)
///
And in your showdialog form by instance
\\\
Dim str As String = DirectCast(Me.Owner, Form1).ListBox1.Items(0).ToString
///

I hope this helps ?

Cor

Nov 21 '05 #5
Thanks again Cor for your help...sorry I didn't mention the "ShowDialog"
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Kevin,

It is the same as the code I showed in a different way.

What you do is passing the reference of that listbox.

Now I know you use that showdialog, than it is easier (and better as well as my first sample) to do it in this way.

\\\
f.ShowDialog(Me)
///
And in your showdialog form by instance
\\\
Dim str As String = DirectCast(Me.Owner, Form1).ListBox1.Items(0).ToString
///

I hope this helps ?

Cor

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: tdmailbox | last post by:
I have form with subform that has a button(one in parent, one in the child) that calls the microsoft access find/replace object. In order to make it a find only object I need to set the...
1
by: news.microsoft.com | last post by:
I am trying to make a customer look up page that can send back the customer Id to the parent page. What is the best way to do this? It is easy in vb.net desktop application, but other than...
1
by: KentG | last post by:
I need a little direction. I'm converting an access database application to a webforms application. My access form has a one to many relationship between the parent and subforms. I would like to...
0
by: Jake Wiley | last post by:
I need to enable a menu item on a parent based on the closing of a child form. I need help in general on how to let the parent know the child has closed. Here are the basic steps I've done: Menu...
0
by: Hardik Shah | last post by:
Hi, I have a child form that has textbox1, I want to add default value for textbox1 but value is not stored to textbox successfully. However , If I run same form directly , it runs successfully....
3
by: Sheikko | last post by:
Hi, i have an application MDI with a TPanel in the left side. THe problem is when I call a child and I maximizie it, it go also under the panel. I have tried to insert another TPanel and include...
11
by: zaaba | last post by:
Hi all. I'm new here and also new in VB programming. Just need a little help from you all. My question is how VB can read data in calendar form. The coding that I create is like this. For Day = 1...
7
by: Darin | last post by:
I have a parent form that has a menu. I then have a child form on the menu. From the child form I need to change the parent form's menu - how can i do that? I tried me.parent.mfavorites, but that...
1
by: scudsong | last post by:
I override ProcessCmdKey() in my MDI parent form class and have some keyboard shortcut calling method in same class. But I wish to make these hotkeys working in parent/child form and other form. The...
0
by: Samuel Jones | last post by:
This article is aimed at beginners, so don't judge me on the quality please. I know many of you are there sitting at your computers looking at the title going 'what is he on about?'. I would too....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.