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。找自己一起交流技術。我相信交流才能快速進步.另外如果覺得用起來不錯,希望給個贊