Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of binding non-bool data CheckBox Control in Windows Form

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about the example analysis of binding non-bool type data CheckBox controls in Windows Form. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

The checked property of CheckBox cannot be directly bound to non-Boolean data, so the following extension is made.

When using it, you need to set two properties first

CheckedValue-the value represented when selected

UnCheckedValue-the value represented if it is not selected

For example

CheckedValue = "male"

UnCheckedValue = "female"

Then bind the data to the bindText property

For example:

EnjoyCheckBox1.DataBindings.Add ("BindText", ds, "cname")

Source code:

Using System

Using System.Collections

Using System.ComponentModel

Using System.Drawing

Using System.Data

Using System.Windows.Forms

Namespace Enjoy.Interface.Control

{

/ / /

/ / A summary description of the EnjoyCheckBox.

/ / /

Public class EnjoyCheckBox: System.Windows.Forms.CheckBox

{

/ / /

/ / required designer variables.

/ / /

Private System.ComponentModel.Container components = null

Public EnjoyCheckBox ()

{

/ / this call is required by the Windows.Forms forms designer.

InitializeComponent ()

/ / TODO: add any initialization after the InitializeComponent call

}

/ / /

/ Clean up all resources in use.

/ / /

Protected override void Dispose (bool disposing)

{

If (disposing)

{

If (components! = null)

{

Components.Dispose ()

}

}

Base.Dispose (disposing)

}

# Code generated by region component designer

/ / /

/ / the designer supports the required methods-do not use the code editor

/ / modify the contents of this method.

/ / /

Private void InitializeComponent ()

{

Components = new System.ComponentModel.Container ()

}

# endregion

Private object m_BindText

Private object m_CheckedValue

Private object m_UnCheckedValue

/ / /

/ / bind properties of the database

/ / /

Public object BindText

{

Get

{

Return m_BindText

}

Set

{

M_BindText = value

If ((masked BindTextents null) & & (CheckedValueVerification null) & & (UnCheckedValueVerification null)

{

If (m_BindText.Equals (CheckedValue))

{

If (! this.Checked)

{

This.Checked = true

}

}

If (m_BindText.Equals (UnCheckedValue))

{

If (this.Checked)

{

This.Checked = false

}

}

}

}

}

/ / /

/ / the value (in the database) represented when selected

/ / /

Public object CheckedValue

{

Get

{

Return m_CheckedValue

}

Set

{

M_CheckedValue = value

}

}

/ / /

/ / the value (in the database) represented if it is not selected

/ / /

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

}

If (! this.Checked)

{

BindText = UnCheckedValue

}

}

}

}

After reading the above, do you have any further understanding of the example analysis of binding a non-bool type data CheckBox control in Windows Form? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report