473,382 Members | 1,376 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,382 software developers and data experts.

Passing Object from form to form.

HI i have a main form which creates a studentDB object, (not acutally a database but an array). I also have a button which creates a new form "addStudentRecord".
Expand|Select|Wrap|Line Numbers
  1.  
  2. public partial class Main : Form
  3.     {
  4.         public StudentDB PrimarySchool;
  5.         public Main()
  6.         {
  7.             InitializeComponent();
  8.             PrimarySchool = new StudentDB("Primary School"); 
  9.         }  
  10.         private void toolStripAddButton_Click(object sender, EventArgs e)
  11.         {
  12.             if (!AddStudentRecord.IsOpen)
  13.             {
  14.                 AddStudentRecord addRecord = new AddStudentRecord(ref     PrimarySchool);
  15.                 addRecord.Show();
  16.  
  17.             } 
  18.         } 
  19.  
As you can see i pass the studentDB object PrimarySchool as a ref to the record. My AddstudentRecord code has an add button which calls a mehtod: PrimarySchool.AddStudent(string Name) to add the student to the array.

Expand|Select|Wrap|Line Numbers
  1. public partial class AddStudentRecord : Form
  2.     {
  3.         public AddStudentRecord(ref StudentDB PrimarySchool)
  4.         {
  5.             InitializeComponent(); 
  6.         } 
  7.         private void AddStudentButton_Click(object sender, EventArgs e)
  8.         {  
  9.             if (!PrimarySchool.Addstudent(NameTextBox.Text)) // PrimarySchool does not exist in current context?
  10.             {
  11.                 MessageBox.Show("Student could not be added");
  12.             }
  13.             else
  14.             {
  15.                 MessageBox.Show("Student added");
  16.             }
  17.          } 
  18.  
However i get an error saying PrimarySchool does not exist in the current context. And PrimarySchool only comes up on the intellisense inside the default constructor of the form? So my question is how do i get the object to be recognised in the onclickEvent of addStudentButton? Or is ther a better way to passed the object to the add student form so it can be accessed by any event.
Apr 26 '08 #1
1 1016
Didnt add a created local object in constructor. Solved it:)
Apr 26 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
2
by: Curtis Justus | last post by:
Hi, I currently have a control that is on a form and I want to pass that exact instance of the control to another form (a child form that appears on a button click). The control has state,...
4
by: Ron Rohrssen | last post by:
I want to show a dialog and when the form (dialog) is closed, return to the calling form. The calling form should then be able to pass the child form to another object with the form as a...
3
by: David K. | last post by:
Hello, I am a novice to C#. Say I have two Windows Form: A and B (not a DialogBox). Suppose I want from Form A object to create and display Form B object (passing it parameters). When closing...
8
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
3
by: Mark | last post by:
Hi From what I understand, you can pass arrays from classic ASP to .NET using interop, but you have to change the type of the.NET parameter to object. This seems to be because classic ASP passes...
6
by: Max | last post by:
Last time I tried to explain this on another forum it didn't go too well, so I'll try my best and if you know what I'm talking about then please tell me how to do this. I have a class, inside I...
13
by: Deano | last post by:
Apparently you can only do this with one value i.e Call MyAssetLocationZoom(Me!txtLocation, "Amend data") This runs; Public Sub MyAssetLocationZoom(ctl As Control, formName As String) On...
7
by: AMP | last post by:
Hello, I have this in form1: namespace Pass { public partial class Form1 : Form { public Form2 form2; public Form1() {
6
by: The Frog | last post by:
Hi Guys, Just wanting some opinions on best method to approach this. I am working on an Access97 db and we have two forms and an ADO connection object to contend with. The desired state is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.