Results 1 to 5 of 5

Thread: Textbox Event

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    Textbox Event

    Greetings, I have a form with 20 Textboxes. When the user leaves the textbox and has changed anything an update has to be written to the DB.
    Is it possible to use only one Eventhandler to cover all Textboxes or do I realy need for every Textbox on this form an own Eventhandler?

    Thankx in advance

  2. #2
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: Textbox Event

    hi,
    In my exp. yes u can.
    in any event you put this code. Instead of using each textbox name.
    ((TextBox)sender).Text

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Köln
    Posts
    395

    Re: Textbox Event

    @popskie:
    thanks - I will try it

  4. #4
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Textbox Event

    You can make the method work for different controls by clicking the events button on the form designer properties, and choosing the method from the drop down list.

    note, that, If you look under "Windows Form Designer code" you will see the IDE adds the handler by using this method:

    Code:
    this.textBox3.Validating += new System.ComponentModel.CancelEventHandler(this.multivalidator);
    Which you could also use yourself programatically at runtime to add event handlers.


    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Textbox Event

    In the designer code, set all of them to have the same event handler, like this for example:

    PHP Code:
        this.textBox1.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
                
    this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
                
    this.textBox3.TextChanged += new System.EventHandler(this.textBox2_TextChanged); 
    Then you can have a look in the event:

    PHP Code:
    private void textBox2_TextChanged(object senderSystem.EventArgs e)
            {
                
    TextBox txtTemp = (TextBox)sender;
                
                
    MessageBox.Show(txtTemp.Name " has changed!");
            } 
    HTH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width