Build a winform control data cache and a winform Control
DataBindingHelper User Manual
1. reference the Rabbit. Core. dll file
That is, my own functional library Rabbit. Core. dll.
Rabbi. Core. DLL Password: dgqv xml annotation password: uxxk
2. Reference a namespace
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 common variable List <FieldBindingContent> fieldList = new List <FieldBindingContent> (); # endregion public Form1 () {InitializeComponent ();} FieldBindingContent fbc; private void Form1_Load (object sender, Eve NtArgs e) {List <a> aas = new List <a> (); aas. add (new a () {ID = "1", dispalyvalue = "male"}); aas. add (new a () {ID = "2", dispalyvalue = ""}); comboBox1.DataSource = aas; comboBox1.ValueMember = "ID"; comboBox1.DisplayMember = "dispalyvalue "; getControlList ();} // bind the control to be operated to public void GetControlList () {fieldList. add (new FieldBindingContent ("name", "Text box", textBox1, "Text", ""); fieldList. add (New FieldBindingContent ("remark", "rich Text box", richTextBox1, "Text", ""); fieldList. add (new FieldBindingContent ("sex", "1", combox1, "SelectedValue", "2"); fieldList. add (new FieldBindingContent ("flag", "true", checkBox1, "Checked", false);} private void button#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. Demo results
5. Main operation instructions I. public FieldBindingContent (string fieldName,
Object fieldValue,
Control bindingControl,
String bindingProperty,
Object defaultValue
)
Mainly through the FieldBindingContent class constructor to bind controls to this class (as a data source)
Parameter description:
/// <Summary>
/// Bind control attributes
/// </Summary>
/// <Param name = "fieldName"> the field name is bound to the tag value of the control to search for the control. </param>
/// <Param name = "fieldValue"> field value, bound to the specified property value of the Control </param>
/// <Param name = "bindingControl"> Control </param>
/// <Param name = "bindingProperty"> control property value </param>
/// <Param name = "defaultValue"> specify the default value of the Control </param>
Example: Read the above code, you know
II. public object GetProperty ()
Parameter description:
/// <Summary>
/// Obtain the property value bound to the current control
/// </Summary>
/// <Returns> returned attribute value </returns>
Example: Read the above code, you know
III. public void SetProperty (object Value );
Parameter description:
/// <Summary>
/// Set the property value of the bound control
/// </Summary>
/// <Param name = "Value"> data to be set </param>
Example: Read the above code, you know
IV. public void SetDefaultProperty ()
Parameter description:
/// <Summary>
/// Restore the initial value of the control Property
/// </Summary>
Example: Read the above code, you know
V. Main attribute display
Public bool AllowNull {get; set ;}
Public Control BindingControl {get; set;} // Control
Public string BindingProperty {get; set;} // property name of the control
Public object DefaultValue {get; set;} // default value of the control
Public object FieldValue {get; set;} // bound property value
Public string FieldName {get; set;} // name of the bound field
6. About
Qq: 739462304. Exchange Technology with yourself. I believe that communication can make rapid progress. In addition, I hope to give a thumbs up