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 350985
In Process

The Archive Base Latest Questions

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

I have a Form with TextBox on it like this: Form f = new

  • 0

I have a Form with TextBox on it like this:

        Form f = new Form();
        TextBox t = new TextBox ();
        t.Click += new EventHandler(t_Click);
        t.LostFocus += new EventHandler(t_LostFocus);

        Testus tt = new Testus();

        t.DataBindings.Add("Left", Testus , "X");
        t.DataBindings.Add("Text", Testus , "Test");

        f.Controls.Add(t);
        f.ShowDialog();

And Testus class like this:

class Testus
{
    public string Test
    {
        get
        {
            return _text;
        }
        set
        {
            Console.WriteLine("Acomplished: text change");
            _text = value;
        }
    }
    private string _text;

    public int X
    {
        get
        {
            return x;
        }
        set
        {
            Console.WriteLine("Acomplished: X changed");
            x = value;
        }
    }
    int x;

    public Testus()
    {

    }
}

As you can see, I bind my TextBox to Testus class. Specifically I bind TextBox.Left to Testus.X and TextBox.Text to Testus.Test. I would like to acomplish that changing Controls Left value will affect Testus.X value and in reverse. And the same for TextBox.Text vs Testus.Test.

I’ve added handlers for Click and LostFocus of my TextBox control like this:

    static void t_LostFocus(object sender, EventArgs e)
    {
        Console.WriteLine("TextBox lost focus");
    }

    static void t_Click(object sender, EventArgs e)
    {
        Console.WriteLine("Moving to right...");
        ((Control)sender).Left = 100;
    }

And I do this test:

  1. run application
  2. enter text into TextBox
  3. Change focus to other control

And I get this results in Console:

TextBox lost focus

And thats it! Testus.Test does not change it’s value!?

But when I do this:

  1. run application
  2. click on textbox (change left value)

I get this results:

Moving to right...
Acomplished: X changed

It seems that Binding Left to X works. And Text to Test not. And when I will change places of bindings to this:

    t.DataBindings.Add("Text", Testus , "Test");
    t.DataBindings.Add("Left", Testus , "X");

Than Text Binding works and left to X binding does not. So in conclusion: only first DataBinding works.

So my quesion is: how to binding two properties of TextBox (Left, Text) to two properties of my object (Testus) (X, Test) so that it will work good?

  • 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:36:05+00:00Added an answer on May 12, 2026 at 11:36 am

    I’ve always done it like this.

    Binding b = new Binding("Test");  
    b.Source = tt;  
    t.SetBinding(TextBox.TextProperty, b);
    
    • 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.