Prem Anandh J

Prem Anandh J

  • NA
  • 492
  • 30.7k

How to Bind static variable with textbox in C# Winform

Dec 22 2015 11:28 PM
Hello all,
 
   How to i want to bind the static variable with textbox.. I tries following
AppStatus.cs
public class AppStatus : INotifyPropertyChanged

{

public static string conxStatus = "Disconnected";

public event PropertyChangedEventHandler PropertyChanged;

protected void NotifyPropertyChanged1(string propertyName)

{

if (this.PropertyChanged != null)

{

PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

}

}

public string _conxStatus

{

get { return conxStatus; }

set

{

if (value != conxStatus)

{

_conxStatus = value;

NotifyPropertyChanged("conxStatus");

}

}

}

}

Form1

public partial class Form1 : Form

{

AppStatus sourceObject;

public Form1 ()

{

InitializeComponent();

sourceObject = new AppStatus();

this.textBox2.DataBindings.Add(new Binding("Text", sourceObject, "_conxStatus", false, DataSourceUpdateMode.OnPropertyChanged));

}

private void button1_Click(object sender, EventArgs e)

{

AppStatus.conxStatus = textBox1.Text;

}

}

Note:
*conxStatus  should be a static then only i can change the value from any form
*but the control TextBox2 not updating
 *It's working in WPF , But not in Winform
post some suggestion.. 
Thanks in advance..
 

Answers (3)