Solved

VB.net modifying a form from another form

Posted on 2003-12-01
2
515 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now