DataBindingHelper使用手册
也就是我自己编写的功能库Rabbit.Core.dll呵呵。
Rabbi.Core.DLL密码:dgqv xml注释 密码:uxxk
using Rabbit.Core;
using System; using System.Windows.Forms; using Rabbit.UI.DataBindingHelper; using System.Collections.Generic; using Rabbit.Core; namespace WindowsFormsApplication3 { public partial class Form1 : Form { #region 共有变量 List<FieldBindingContent> fieldList = new List<FieldBindingContent>(); #endregion public Form1() { InitializeComponent(); } FieldBindingContent fbc; private void Form1_Load(object sender, EventArgs e) { List<a> aas = new List<a>(); aas.Add(new a() { ID = "1", dispalyvalue = "男" }); aas.Add(new a() { ID = "2", dispalyvalue = "女" }); comboBox1.DataSource = aas; comboBox1.ValueMember = "ID"; comboBox1.DisplayMember = "dispalyvalue"; GetControlList(); } //将需要操作的控件进行绑定 public void GetControlList() { fieldList.Add(new FieldBindingContent("name", "文本框", textBox1, "Text", "")); fieldList.Add(new FieldBindingContent("remark", "富文本框", richTextBox1, "Text", "")); fieldList.Add(new FieldBindingContent("sex", "1", comboBox1, "SelectedValue", "2")); fieldList.Add(new FieldBindingContent("flag", "true", checkBox1, "Checked", false)); } private void button1_Click(object sender, EventArgs e) { foreach (FieldBindingContent item in fieldList) { if (item.FieldName != "sex") { continue; } label5.Text = item.FieldValue.ToString(); } } private void button2_Click(object sender, EventArgs e) { foreach (FieldBindingContent item in fieldList) { item.SetDefaultProperty(); } } private void button3_Click(object sender, EventArgs e) { foreach (FieldBindingContent item in fieldList) { if (item.FieldName == "remark") item.SetProperty("hello!"); } } private void button4_Click(object sender, EventArgs e) { foreach (FieldBindingContent item in fieldList) { if (item.FieldName == "flag") label6.Text = item.GetProperty().ToString(); } } private void label5_Click(object sender, EventArgs e) { } } public class a { public string ID { get; set; } public string dispalyvalue { get; set; } } }
)
主要是通过FieldBindingContent类的构造函数来实现控件于该类(作为数据源)的绑定
参数说明:
/// <summary>
/// 绑定控件属性
/// </summary>
/// <param name="fieldName">字段名绑定在控件的tag值上,以便搜索该控件</param>
/// <param name="fieldValue">字段值,绑定控件的指定属性值</param>
/// <param name="bindingControl">控件</param>
/// <param name="bindingProperty">控件属性值</param>
/// <param name="defaultValue">指定控件默认值</param>
示例:看上面的代码,你懂的
参数说明:
/// <summary>
/// 获取当前控件绑定的属性值
/// </summary>
/// <returns>返回属性值</returns>
示例:看上面代码,你懂的
参数说明:
/// <summary>
/// 设置绑定的控件的属性值
/// </summary>
/// <param name="Value">待设置的数据</param>
示例:看上面代码,你懂的
参数说明:
/// <summary>
/// 控件属性恢复初始值
/// </summary>
示例:看上面代码,你懂的
public bool AllowNull { get; set; }
public Control BindingControl { get; set; }//控件
public string BindingProperty { get; set; }//控件的属性名
public object DefaultValue { get; set; }//控件的默认值
public object FieldValue { get; set; }//绑定的属性值
public string FieldName { get; set; }//绑定的字段名
本人qq:739462304。找自己一起交流技术。我相信交流才能快速进步.另外如果觉得用起来不错,希望给个赞