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
Solved

Form Delegation

Posted on 2004-08-18
12
185 Views
Last Modified: 2010-04-15
I have two Forms. In form1 there are two textBoxes, i'm trying to refrence these two textBoxes in Form2. I'm having problem refrencing them. I need to call these two textBoxes inorder to authenticate users. Both these textBoxes have been made public.
Also i have tabPages in form2,from tabPage2, by a click of a button i'm trying to pen tabPage3, but having problem with this too. This is mainly due to authentication problem. Heres the code:

private void button1_Click(object sender, System.EventArgs e)
            {
                  SqlConnection da = new SqlConnection(
                        @"Data Source= xxxxxx;"+
                        "Initial Catalog = xxxx;" +
                        "Network Library=DBMSSOCN;"+
                        "user id =xx;"+
                        "Password=xxxx");
                  da.Open();
            SqlCommand thisCommand = da.CreateCommand();
                  
                  String sQuery = "SELECT Name, LicenseID FROM License WHERE Name = '"+ Form1.textBox1.Text +"' AND LicenseID = '"+ Form1.textBox2.Text +"'";
                  SqlCommand cmd = new SqlCommand(sQuery, da);
                  SqlDataReader dr = cmd.ExecuteReader();
                  if(dr.Read()){
                  tabPage3.Show();
                  label3.Text = dr[ "Name" ].ToString();}
                  da.Close();
            }
What do i need to do inorder to solve this scenario.
Thanks,
Les


0
Comment
Question by:lesmydad
  • 5
  • 4
12 Comments
 
LVL 9

Expert Comment

by:msdixon
ID: 11843341
i would include two string properties in the constructor of the child form. when you open up the form, pass the values of the two text boxes in. saves a lot of trouble. then other forms can also use this child form without difficulty.
0
 
LVL 1

Author Comment

by:lesmydad
ID: 11846921
How would  go about implementing the string properties constructors, i nneed to pasds the value from the parent form to the child form. I'm mainly having problem referncing the event from form1 to form2.
Any script exeample will be apprechiated.
Thanks
0
 
LVL 9

Expert Comment

by:msdixon
ID: 11849194
well, how are you opening form2?

here's some pseudo code...

public class form2
{
   private string _name, _licenseId;
   public form2 (string name, string licenseId)
   {
      _name = name;
      _licenseId = licenseId;
   }
}

now within form1, when you open the second form

form2 frm = new form2(textBox1.Text, textbox2.Text);
// for instance if it's a dialog
frm.ShowDialog();
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 1

Author Comment

by:lesmydad
ID: 11851616
Hi msdixon,
With the above code i get an errors, firstly
new Form2 i
s not recognised it gives this error: No overload for method 'Form2' takes '2' arguments
and secondly how do i declare the textBoxes at present i,m doing it like Form1.textBox1.Text , but this gives error of referencing problem. As form1. is not recognised.

If i declkare the textBoxes like this "textBox1.Text", then the compiler does not recognise the attribute as there are'nt any textBoxes in form2.

I'm openning my form like this:

this.Visible = false;
                        Form2 frm = new Form2(textBox1.Text, textBox2.Text);
                        frm.ShowDialog();
                        this.Close();

What i'm mainly trying to do, is get the sql command to recognise the valus from textBoxes in form1 into form2.

Thanks,
Les

0
 
LVL 9

Expert Comment

by:msdixon
ID: 11856469
you need to modify the constructor in form2 with the code i posted

public class Form2...
0
 
LVL 1

Author Comment

by:lesmydad
ID: 11861770
Hi msdixon,
Done what u told me to do, modifing the form2 constructor, still no luck. The same old problems turns up as mentioned beodfre Form1.extboxes.Text are not recognised as its not refrenced and the "new" part of new Form2(textBox1.Text, textBox2.Text); throws an error of:

C:\Documents and Settings\encode\Desktop\WindowsApplication5\Form1.cs(178): No overload for method 'Form2' takes '2' arguments

Any other solutions,recommendations.
Thanks
Les
0
 
LVL 9

Accepted Solution

by:
msdixon earned 250 total points
ID: 11870268
it's case sensitive, so if you pasted my code, it won't match up to yours. it needs to be:

   public Form2 (string name, string licenseId)
   {
      // set your variable values here
   }
0
 
LVL 1

Author Comment

by:lesmydad
ID: 11879597
Thanks, this function correctly, but having problem with openning tabPage3. From tabPage2 when clicked on a button tabPage3 should open. Both tabPages are on form2, so no delegation is involved. I could open tabPage2 from tabPage3, but vice-versa does not take place.
Any idea why.
Thanks
0
 
LVL 9

Expert Comment

by:msdixon
ID: 12070613
i am interested in the final disposition, i just don't want to write all of his code for him.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

837 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