?
Solved

Building LoginID from multiple textBox Strings

Posted on 2005-05-04
5
Medium Priority
?
271 Views
Last Modified: 2011-09-20
Hi,

I have a C# windows form built.  I want to get input from the user and build a loginID from that input.  So for example.  I have 3 textboxes.  the first is for input of the first name.  The second is for input of the last name.  The third textbox should display the last three chars of the lastname combined with the first 2 chars of the first name.

I want this to happen dynamically as the user types in the name.  I understand how to break the string apart into chars but I am unclear where to put this code so it updates the third textbox as the user types the data in.

Thanks for your help
darkstag@earthlink.net
0
Comment
Question by:darkstagg
5 Comments
 
LVL 3

Assisted Solution

by:mpf1748
mpf1748 earned 400 total points
ID: 13928415
You will need to add a TextChanged listener for the first two textboxes (i.e. first name and last name). Have both call the same method GenID (for example). Put the code in GenID to set the text of the third textbox to the logic you have defined.
0
 

Author Comment

by:darkstagg
ID: 13928547
This is where I am having the problem.  I am unclear on the TextChanged listener.  Is it a seperate method and how do I activate it.  Is there an example somewhere. Im sorry to be so confused.  I am a little new at C#.

Thanks
darkstag@earthlink.net
0
 
LVL 8

Assisted Solution

by:rajaloysious
rajaloysious earned 600 total points
ID: 13928608
this.textbox1.TextChanged += new System.EventHandler(this.TextBox1or2_TextChanged);
this.textbox2.TextChanged += new System.EventHandler(this.TextBox1or2_TextChanged);


private void TextBox1or2_TextChanged(object sender, System.EventArgs e)
{
//Here comes your code to update textbox3      something like below
//textbox3.Text = textbox1.Text.Substring(0,3) + textbox2.Text.Substring(0,5)
      
}

cheers
0
 
LVL 2

Accepted Solution

by:
wmatos earned 1000 total points
ID: 13928635
I am calling the first text box txtFirst and the 2nd txt box txtLast and the third textbox txtUID.

Set the TextChanged event for txtFirst AND txtLast to this method:
            private void txtbox_TextChanged(object sender, System.EventArgs e)
            {
                  string firstpre = "";
                  string lastpost = "";
                  string firsttxt = txtFirst.Text.Trim();
                  if(firsttxt.Length < 3){firstpre = firsttxt;}
                  else{firstpre = firsttxt.Substring(0,2);}
                  string lasttxt = txtLast.Text.Trim();
                  if(lasttxt.Length < 4){lastpost = lasttxt;}
                  else{lastpost = lasttxt.Substring(lasttxt.Length - 4);}
                  txtUID.Text = firstpre + lastpost;

            }
0
 

Author Comment

by:darkstagg
ID: 13928638
Very cool thanks.  Thats where I was going wrong on the textbox part.  Now I do have it accurately reacting on change.  It looks like I havent quite figured out the character input part yet. But I will give it a try before asking for more from you.

Sincere thanks I really appreciate it.

darkstag@earthlink.net
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

862 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