Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 349743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:29:12+00:00 2026-05-12T11:29:12+00:00

I have a TextBox and I change it’s Left value. And this TextBox is

  • 0

I have a TextBox and I change it’s Left value. And this TextBox is bound to a class that have X property. Now when I change Left value of my TextBox I would like to have X of my class updated. What should i do to force update of my databound class property?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T11:29:13+00:00Added an answer on May 12, 2026 at 11:29 am

    Because of how data-binding works, this type of 2-way binding will only work if the control advertises changes; usually via a *Changed event – i.e. LeftChanged in this case. Since there is no such event, you simply can’t, short of subclassing TextBox, re-declaring (new) Left and adding a LeftChanged that hooks off LocationChanged.

    Can you just add an event to LocationChanged and do it manually? Or just update the object manually when you set the location/left?


    using System;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        class SuperTextBox : TextBox
        {
            protected override void OnLocationChanged(EventArgs e)
            {
                base.OnLocationChanged(e);
    
                EventHandler handler = (EventHandler)Events[LeftChangedKey];
                if (handler != null) handler(this, EventArgs.Empty);
            }
            public event EventHandler LeftChanged
            {
                add { Events.AddHandler(LeftChangedKey, value); }
                remove { Events.RemoveHandler(LeftChangedKey, value); }
            }
            public new int Left
            {
                get { return base.Left; }
                set { base.Left = value; }
            }
            private static readonly object LeftChangedKey = new object();
        }
        class Person {
            private int value;
            public int Value {
                get {return value;}
                set {
                    this.value = value;
                    EventHandler handler = ValueChanged;
                    if(handler!=null)
                    {
                        handler(this, EventArgs.Empty);
                    }
                }
            }
            public event EventHandler ValueChanged;
        }
        static class Program
        {
            static void Main()
            {
                Button btn;
                TextBox txt;
                Person p = new Person { Value = 10 };
                using (Form form = new Form {
                    DataBindings = {{ "Text", p, "Value"}},
                    Controls = {
                        (txt = new SuperTextBox {
                            DataBindings = {{ "Left", p, "Value", false,
                                DataSourceUpdateMode.OnPropertyChanged}}
                        }),
                        (btn = new Button {
                            Text = "bump",
                            Dock = DockStyle.Bottom
                        })
                    }
                }) {
                    btn.Click += delegate { txt.Left += 5; };
                    Application.Run(form);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.