通過構造數據源,將控制項的屬性與其綁定,隨時能對一系列控制項屬性值的取值和賦值。方便監控需要增刪改查的控制項數據。不需要Control.Text來獲取該控制項的值了。一步到位,直接拿到控制項的值進行操作。 ...
DataBindingHelper使用手冊
1.引用Rabbit.Core.dll文件
也就是我自己編寫的功能庫Rabbit.Core.dll呵呵。
Rabbi.Core.DLL密碼:dgqv xml註釋 密碼:uxxk
2.引用命名空間
using Rabbit.Core;
3.示例demo
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; } } }
4.演示效果
5.主要操作方法說明
I.public FieldBindingContent(string fieldName,
object fieldValue,
Control bindingControl,
string bindingProperty,
object defaultValue
)
主要是通過FieldBindingContent類的構造函數來實現控制項於該類(作為數據源)的綁定
參數說明:
/// <summary>
/// 綁定控制項屬性
/// </summary>
/// <param name="fieldName">欄位名綁定在控制項的tag值上,以便搜索該控制項</param>
/// <param name="fieldValue">欄位值,綁定控制項的指定屬性值</param>
/// <param name="bindingControl">控制項</param>
/// <param name="bindingProperty">控制項屬性值</param>
/// <param name="defaultValue">指定控制項預設值</param>
示例:看上面的代碼,你懂的
II. public object GetProperty()
參數說明:
/// <summary>
/// 獲取當前控制項綁定的屬性值
/// </summary>
/// <returns>返回屬性值</returns>
示例:看上面代碼,你懂的
III. public void SetProperty(object Value);
參數說明:
/// <summary>
/// 設置綁定的控制項的屬性值
/// </summary>
/// <param name="Value">待設置的數據</param>
示例:看上面代碼,你懂的
IV. public void SetDefaultProperty()
參數說明:
/// <summary>
/// 控制項屬性恢復初始值
/// </summary>
示例:看上面代碼,你懂的
V.主要屬性展示
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; }//綁定的欄位名
6.關於
本人qq:739462304。找自己一起交流技術。我相信交流才能快速進步.另外如果覺得用起來不錯,希望給個贊