views:

50

answers:

2

Hi all i have main form with a treeview control with a set of files displayed under each node. If i had my mouse over that node i will read the values that are present in the text file by using the following code

 private void treeViewACH_NodeMouseHover(object sender, TreeNodeMouseHoverEventArgs e)
    {
        string strFile = string.Empty;
        System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
        messageBoxCS.AppendFormat(" {0}", e.Node);
        strFile = messageBoxCS.ToString().Substring(11);
        strFilePath = Directory.GetCurrentDirectory();
        strFilePath = Directory.GetParent(strFilePath).ToString();
        strFilePath = Directory.GetParent(strFilePath).ToString();
        strFilePath = strFilePath + "\\ACH" + "\\" + strFile;


        if ((File.Exists(strFilePath)))
        {
            StreamReader sr = new StreamReader(strFilePath);
            StringComparison compareType = StringComparison.InvariantCultureIgnoreCase;
            string fileName = Path.GetFileNameWithoutExtension(strFilePath);
            string extension = Path.GetExtension(strFilePath);
            if (fileName.StartsWith("FileHeader", compareType)
                && extension.Equals(".txt", compareType))
            {
                string s = sr.ReadToEnd();
                StringBuilder sb = new StringBuilder();
                //sb.Append("RecordTypeCode\tPriorityCode");
                //sb.Append("\n");
                //sb.Append("--------------------------------------------------");
                //sb.Append("\n");
                objFile.ReferenceTypeCode = s.Substring(0, 1);
                sb.Append(objFile.ReferenceTypeCode);
                string PriorCode = s.Substring(1, 2);
                sb.Append(PriorCode);
                objFile.getValues(sb.ToString());
                frmTemp frmtemp = new frmTemp();
                frmtemp.Show();

            }
        }

Now i would like to place the values in each textboxes on the form load. But as it is a different form i can not access the values from the business layer

I have coded like this on form load

         BL.FileHeader objFile = new FileHeader();
         private void frmTemp_Load(object sender, EventArgs e)
    {
        textBox1.Text = objFile.ReferenceTypeCode;
    }

But i am unable to display the values any help please..

+1  A: 

Add a property to your frmTemp class for each value that you want to display. In your NodeMouseHover handler, assign values to those properties right after you create the instance of the form. Then, in the frmTemp_Load handler, assign the values of those properties to the TextBox controls.

can you please explain in detail with a sample code
Dorababu
A: 

Got the answer by the following

           frmTemp frmtmp = new frmTemp(strFileHeader);
            frmtmp.Show();

      public frmTemp(string str)
    {
        InitializeComponent();
        if (str.StartsWith("1"))
        {
            this.textBox1.Text = str.Substring(0, 1);
        }
        else if (str.StartsWith("5"))
        {
            this.textBox1.Text = str.Substring(0, 1);
            this.textBox2.Text = str.Substring(4, 16);
        }
    }
Dorababu