本文整理汇总了C#中System.Windows.Forms.Binding.WriteValue方法的典型用法代码示例。如果您正苦于以下问题:C# Binding.WriteValue方法的具体用法?C# Binding.WriteValue怎么用?C# Binding.WriteValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Binding
的用法示例。
在下文中一共展示了Binding.WriteValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindSelectedIndexChanged
// We need to force WriteValue() on SelectedIndexChanged otherwise it will only call WriteValue()
// on loss of focus.
// http://stackoverflow.com/questions/1060080/databound-winforms-control-does-not-recognize-change-until-losing-focus
/// <summary>
/// Binds the specified combobox
/// </summary>
/// <param name="cmb"></param>
/// <param name="b"></param>
/// <returns></returns>
public static Binding BindSelectedIndexChanged(ComboBox cmb, Binding b)
{
cmb.DataBindings.Add(b);
cmb.SelectedIndexChanged += (sender, e) => { b.WriteValue(); };
return b;
}
示例2: BindValueChanged
// We need to force WriteValue() on CheckedChanged otherwise it will only call WriteValue()
// on loss of focus.
// http://stackoverflow.com/questions/1060080/databound-winforms-control-does-not-recognize-change-until-losing-focus
/// <summary>
/// Binds the specified NumericUpDown control
/// </summary>
/// <param name="num"></param>
/// <param name="b"></param>
/// <returns></returns>
public static Binding BindValueChanged(NumericUpDown num, Binding b)
{
num.DataBindings.Add(b);
num.ValueChanged += (sender, e) => { b.WriteValue(); };
return b;
}
示例3: BindText
// We need to force WriteValue() on TextChanged otherwise it will only call WriteValue()
// on loss of focus.
// http://stackoverflow.com/questions/1060080/databound-winforms-control-does-not-recognize-change-until-losing-focus
/// <summary>
/// Binds the specified text box
/// </summary>
/// <param name="txt"></param>
/// <param name="b"></param>
/// <returns></returns>
public static Binding BindText(TextBoxBase txt, Binding b)
{
txt.DataBindings.Add(b);
txt.TextChanged += (sender, e) =>
{
b.WriteValue();
};
return b;
}
示例4: DataSourceNullValueTest
public void DataSourceNullValueTest ()
{
Control c = new Control ();
c.BindingContext = new BindingContext ();
c.CreateControl ();
ChildMockItem item = new ChildMockItem ();
item.ObjectValue = "A";
Binding binding = new Binding ("Tag", item, "ObjectValue");
binding.DataSourceNullValue = "NonNull";
c.DataBindings.Add (binding);
Assert.AreEqual (c.Tag, "A", "#A1");
// Since Tag property doesn't have a
// TagChanged event, we need to force an update
c.Tag = null;
binding.WriteValue ();
Assert.AreEqual (item.ObjectValue, "NonNull", "#B1");
}
示例5: WriteValueTest
public void WriteValueTest ()
{
Control c = new Control ();
c.BindingContext = new BindingContext ();
c.CreateControl ();
MockItem item = new MockItem ();
item.Text = "A";
Binding binding = new Binding ("Text", item, "Text");
binding.DataSourceUpdateMode = DataSourceUpdateMode.Never;
c.DataBindings.Add (binding);
Assert.AreEqual ("A", c.Text, "#A1");
c.Text = "B";
Assert.AreEqual ("A", item.Text, "#B1");
binding.WriteValue ();
Assert.AreEqual ("B", item.Text, "#C1");
}