Solved

VB.net modifying a form from another form

Posted on 2003-12-01
2
517 Views
Last Modified: 2010-05-18
I have a main form called MainScreen. I have a listbox in this MainScreen that I am trying to update from another form(form2). I am clicking a button in form2, and I want it to add something to the listbox in MainScreen. I have tried just doing MainScreen.listbox.items.add("FFFF"), but that doesn't seem to work. I have also tried creating variables of type MainScreen and doing it that way, but I get an error(Object reference not set to an instance of an object). I have also tried creating a function in MainScreen:
    Public Sub AddItemToList(ByVal listitem As String)
    mylistbox.item.add(listitem)
    End Sub
and calling that function from form2, but get that same error.

Should I be making MainScreen the parent of form2 somehow? Any help would be appreciated.
0
Comment
Question by:dnk99
2 Comments
 
LVL 27

Accepted Solution

by:
Dabas earned 125 total points
ID: 9855872
Hi dnk99,
I assume that somewhere in MainScreen you have something like this:

Dim f as new Form2
f.Show

To solve your problem, you need to add two lines to your program.

In form2, add the following line:

Public fMainScreen as MainScreen

In MainScreen, add the following line before f.Show:

f.FMainScreen = Me

Now you will be able to do what you want:

fMainScreen.ListBox.Items.Add("FFFF")

Dabas
0
 

Author Comment

by:dnk99
ID: 9856077
Thanks Dabas. Works perfectly.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Server Error 11 58
start a process from a service 3 21
Store results in vb.net 3 20
Please explain the parts of these 2 LINQ expressions 3 27
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question