?
Solved

VB.net modifying a form from another form

Posted on 2003-12-01
2
Medium Priority
?
522 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

762 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