当前位置:网站首页>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会变化吗?
边栏推荐
- 数据库概论之MySQL表的增删改查2
- Day 4 of HCIP
- postgres 多个变量填充字符串,字串格式化
- Leetcode周赛304
- 享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世
- MySQL driver jar package download -- nanny tutorial
- CAT1 4G+以太网开发板腾讯云手机微信小程序显示温度和下发控制
- File upload vulnerability (2)
- 文件上传漏洞(二)
- At age 94, pioneer Turing award winner, computational complexity theory, Juris Hartmanis, died
猜你喜欢
HCIP day one
The nacos source code can not find the istio package
Facebook社媒营销的5大技巧,迅速提高独立站转化率!
Nodejs installation and global configuration (super detailed)
Pagoda+FastAdmin 404 Not Found
[Dataset][VOC] Male and female dataset voc format 6188 sheets
(Part of it is not understood, and the notes are not completed) [Graph Theory] Difference Constraints
数据库概论之MySQL表的增删改查2
(Notes are not completed) [Graph Theory] Traversal of graphs
chrome plugin development guide
随机推荐
MySQL 5.7 installation tutorial (full-step, nanny-level tutorial)
解决C#非静态字段、方法或属性“islandnum.Program.getIslandCount(int[][], int, int)”要求对象引用
love
Expert Insights | 3 ways to seize innovation opportunities in a downturn
交换--STP协议
两篇不错的php debug教程
Swagger的简单介绍,集成,以及如何在生产环境中关闭swagger,在测试和开发环境中自动打开
MySQL Advanced Study Notes
About the local server problem after ue4.27 pixel streaming package
SimpleChannelInboundHandler使用总结
JS初识高阶函数和函数柯里化
【21天学习挑战赛】顺序查找
Nodejs installation and global configuration (super detailed)
Day 4 of HCIP
Leetcode周赛304
MySQL (3)
chrome plugin development guide
笔记本开机黑屏提示:ERROR 0199:System Security-Security password retry count exceeded
docker 安装mysql
正则表达式的理解学习