Passing values

Posted on 2012-03-24
Last Modified: 2012-03-25

How can pass value from a Form to a Class in c# 2010?

Please help.

Question by:ayha1999
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
LVL 10

Assisted Solution

himanshut earned 250 total points
ID: 37762282
You can use Sessions to store values that you have to pass and then pass those Session Values to method that can be used by creating instance of the Class( so that all the methods of that class can be accessed).
LVL 10

Accepted Solution

Umar Topia earned 250 total points
ID: 37762293
You can create a method in class which you can call with parameters like:

MyClass mc = new MyClass();

or else you can create the parameterised Constructor

MyClass mc = new MyClass(sFirstName,sLastName);

Author Comment

ID: 37762456
here I am trying access value from Form2 class into dbo2 class but ended up with error. how can I access txtRef in the dbo2 class?

the error

Error      1      The name 'txtRef' does not exist in the current context      

namespace myProject
   public partial class Form2: Form
       public Form2 ( )
          InitializeComponent ();

       private void Form2_Load (object sender, EventArgs e)


       private string txtRef=string.Empty;

       public string _Ref
          set { txtRef=value; }

   public class dob2: DataSet
       private DataTable dt2;
       string str = txtRef;   <--- values to be accepted here.

       public dob2 ( )



Author Closing Comment

ID: 37762879

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
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: …

689 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