Binding the textBox border color.

3 posts, 0 answers
  1. Igor
    Igor avatar
    4 posts
    Member since:
    Nov 2010

    Posted 06 Feb 2012 Link to this post

    Hello,

    In order to change the border color of the TextBox i use:
    textBox1.TextBoxElement.Border.ForeColor = Color.Red;
    How can i achieve this using data binding?
    
    Looking forward to your reply.      
  2. Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 07 Feb 2012 Link to this post

    Hi Igor,

    Thank you for writing.

    You can use the simple binding mechanism to bind the ForeColor property to the Text property of another control, for example:
    RadTextBox textBox1 = new RadTextBox();
    RadTextBox textBox2 = new RadTextBox();
    textBox1.DataBindings.Add("Text", textBox2.TextBoxElement.Border, "ForeColor", true, DataSourceUpdateMode.OnPropertyChanged);

    I hope this helps. Feel free to ask if you have any additional questions.  

    Kind regards,
    Juliana
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Boryana
    Admin
    Boryana avatar
    330 posts

    Posted 08 Feb 2012 Link to this post

    Hi Igor,

    Please consider the following approach:
    public partial class Form1 : Form
    {
        private void Form1_Load(object sender, EventArgs e)
        {
            this.myTextBox1.DataBindings.Add("BorderColor", MyObj, "Color");
        }
    }
     
    public class MyTextBox : RadTextBox
    {
        public Color BorderColor
        {
            get
            {
                return this.TextBoxElement.Border.ForeColor;
            }
            set
            {
                this.TextBoxElement.Border.ForeColor = value;
                OnNotifyPropertyChanged("BorderColor");
            }
        }
     
        public override string ThemeClassName
        {
            get
            {
                return typeof(RadTextBox).FullName;
            }
        }
    }

    I hope this is the solution you are looking for. Let me know if you have further questions.

    Kind regards,
    Boryana
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top