Click here to Skip to main content
15,903,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, i have one Main form, and i have tab control and tab pages, Inside tab pages i used User Control. In Main form I have datetime.Text(Label), and i wanted to call/get value of it to tab page (which is the user control) tell me how to make the datetime.Text global, so that i can get the value of it. Thanks , sorry for my bad english

here's the pic, Please copy and paste the link to browser to view the image tinypic.com/view.php?pic=2w20yg4&s=9
Posted
Updated 30-Oct-15 22:21pm
v2
Comments
BillWoodruff 31-Oct-15 7:30am    
1. the link to your picture is broken: it leads back to this page

2. looking at your picture, I don't see anywhere in the Foreclosed Tab being displayed where there is a DateTime field, or somewhere a Date will be displayed: please clarify the question.

3. in your picture it's not clear exactly what is the UserControl: please clarify; is everything in the Foreclosed Tab in the UserControl ?
Rencyrence 1-Nov-15 20:00pm    
Hi bill, I just added parameters to the foreclosed, wherein Datetime.label will be automatically inserted in the database without using field

Hi, declare a common class to hold common information which are needed in the lifetime of an application, it is the convenient way to store and access common information. Create a Class named CommonInfo like below, and create a string property named DateTimeInfo to hold DateTime information.
C#
public static class CommonInfo
{
  private static string _DateTimeInfo = string.Empty;

  public static string DateTimeInfo
  {
    get { return _DateTimeInfo; }
    set { _DateTimeInfo = Value; }
  }
}

Now you can store and access information to DateTimeInfo from anywhere inside your project. Assign the DateTime information to CommonInfo.DateTimeInfo property when you load the main form. In the Load event of Main form assign DateTime information like this,
C#
CommonInfo.DateTimeInfo = your expression;

Now you can get this from your tab pages. For that just use CommonInfo.DateTimeInfo.
 
Share this answer
 
Comments
Rencyrence 1-Nov-15 20:04pm    
i change ur code to set {_DateTimeInfo = datetimelabel.text;} doesnt work :(
VR Karthikeyan 1-Nov-15 22:45pm    
don't change it, leave it as set {_DateTimeInfo = Value;}
Rencyrence 2-Nov-15 22:22pm    
Thanks!
Don't.
Globals are not only pretty much unnecessary in C#, they break all the advantages of OOPs design.

In this case, it would mean that you can't "reuse" the usercontrol in multiple places, or outside the main form or current application.

Instead, add a property or method to the control which lets the container set the DateTime value directly.
See here: Transferring information between two forms, Part 1: Parent to Child[^] - it's forms based but teh exact same code works for controls as well. Your form is the "Parent", your control is the "Child".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900