?
Solved

VB.net modifying a form from another form

Posted on 2003-12-01
2
Medium Priority
?
525 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 500 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

807 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