Checkbox controls for non-Bool type data can be bound in Windows Form

zhaozj2021-02-08  260

Checkbox's Checked attribute cannot directly bind non-BOOL type data, so this extension is made.

When using it, you need to set two attributes CheckedValue ---- Select the value of the Time table uncheckedValue ---- The value of the unselected time table

For example, CheckedValue = "Men" UncheckedValue = "Female" then binds data to bindtext attribute

For example: enjoyCheckBox1.Databindings.add ("Bindtext", DS, "CNAME");

Source: using system.collections; using system.dawing; using system.data; using system.windows.form;

Namespace enjoy.Interface.control {///

/// EnjoyCheckbox's summary description. /// public class enjoyCheckbox: system.windows.Forms.checkbox {/// // The designer variable is required. /// private system.componentmodel.container components = null;

Public EnjoyCheckbox () {// This call is required for the Windows.Forms Form Designer. InitializationComponent ();

// Todo: Add any initialization after INITIALIZECMPONENT call

}

///

/// Clean all the resources being used. /// Protected Override Void Dispose (Bool Disposing) {if (disponents! = Null) {components.dispose ();}} Base.Dispose

#REGION component designer generated code ///

/// designer supports the required method - Do not use the code editor // to modify the contents of this method. /// private vid initializecomponent () {components = new system.componentmodel.container ();} #ENDREGION

private object m_BindText; private object m_CheckedValue; private object m_UnCheckedValue; ///

/// binding properties database /// public object BindText {get {return m_BindText;} set {m_BindText = value; if ((m_bindtext! = null) && (cHECKEDVALUE! = null) && (uncheckedValue! = null) {if (m_bindtext.equals (checkedvalue)) {if (! this.checked) {this.Checked = true;}} (M_BindText.Equals (uncheckedValue) {if (this.checked) {this.checked = false;}}}}} /// /// select the time table (in the database) value /// < / summary> public object checkedvalue {get {return m_CheckedValue;} set {m_checkedvalue = value;}}

///

/// value represents when not selected (in the database) /// public object UnCheckedValue {get {return m_UnCheckedValue;} set {m_UnCheckedValue = value;}} protected override void OnCheckedChanged ( Eventargs e) {base.oncheckedchanged (e); if (this.checked) {bindtext = CheckedValue;}}} (! This.checked) {bindtext = uncheckedValue;}}

}

For the first time, please reply anything or suggestions.

转载请注明原文地址:https://www.9cbs.com/read-2409.html

New Post(0)