当前位置:网站首页>ADS通信--倍福PLC和C#TextBox控件实现数据绑定的方法
ADS通信--倍福PLC和C#TextBox控件实现数据绑定的方法
2022-08-02 06:21:00 【黄昏和星空】
经常写用一个TextBox显示某个对象,然后编辑之后再保存的程序。以前都是在TextBox_TextChanged事件中修改对象的值,或者保存的时候再读取TextBox.Text属性保存对象的值。这样比较麻烦,而且经常容易出错。后来了解了C#的数据绑定,发现能够很好的解决这个问题。
- 首先C#的TextBox本身就带数据绑定功能。
下面的代码就是把_myData对象的"TheValue"属性绑定到textBox1和textBox2的"Text"属性。最后一个参数不同:
1)其中DataSourceUpdateMode.OnPropertyChanged表示textBox1.Text发生变化,_myData.TheValue也变化,叫双向绑定。
2)DataSourceUpdateMode.Never表示Text1.Text变化不影响_myData.TheValue的值,是单向绑定。
?
1
2
3
4
5
6
private void Form1_Load(object sender, EventArgs e)
{
_myData = new MyData();
textBox1.DataBindings.Add(“Text”, _myData, “TheValue”, false, DataSourceUpdateMode.OnPropertyChanged);
textBox2.DataBindings.Add(“Text”, _myData, “TheValue”, false, DataSourceUpdateMode.Never);
}
2.也许有人留意到了,为什么上面的叫"双向绑定"呢?如果_myData.TheValue的值变化了,两个文本框的Text会变化吗?
边栏推荐
- aTrust项目的相关操作与分享
- HCIP 第三天实验
- 【npm install 报错问题合集】- npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
- chrome 插件开发指南
- 技术管理三级跳
- SphereEx苗立尧:云原生架构下的Database Mesh研发实践
- MySQL Advanced SQL Statements
- 【暑期每日一题】洛谷 P3156 【深基15.例1】询问学号
- punch day05
- See the picture to understand | How to choose sales indicators to measure the health of business growth
猜你喜欢

第06章 索引的数据结构【2.索引及调优篇】【MySQL高级】

交换--STP协议

MySQL 5.7 installation tutorial (full-step, nanny-level tutorial)

文件上传漏洞(二)

聊天机器人如何提升独立站的营销水平?

The second day HCIP

Day 4 of HCIP

实验8 VLAN综合实验

Toolbox App 1.25 New Features at a Glance | Version Update

【npm install 报错问题合集】- npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
随机推荐
ue先视频教程后深入
(Part of it is not understood, and the notes are not completed) [Graph Theory] Difference Constraints
振兴农村循环经济 和数链串起农业“生态链”
实例028:递归求等差数列
How the Internet of Things is changing the efficiency of city operations
SphereEx苗立尧:云原生架构下的Database Mesh研发实践
.NET Static Code Weaving - Rougamo Release 1.1.0
At age 94, pioneer Turing award winner, computational complexity theory, Juris Hartmanis, died
专家见解|经济低迷期把握创新机会的 3 大方法
pointer arithmetic in c language
[npm install error report collection] - npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
optional
.NET静态代码织入——肉夹馍(Rougamo) 发布1.1.0
文件上传漏洞(二)
HCIP 第四天
August 2022 plan, focusing on ue4 video tutorials
2022.07.31(LC_6133_分组的最大数量)
[21天学习挑战赛——内核笔记](一)——设备树的概述(硬件、目标、效果、文件类型)
实例031:字母识词
Resolving C# non-static field, method or property "islandnum.Program.getIslandCount(int[][], int, int)" requires an object reference