当前位置:网站首页>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会变化吗?
边栏推荐
- SphereEx苗立尧:云原生架构下的Database Mesh研发实践
- 享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世
- Go inside the basic knowledge
- Specified URL is not reachable,caused by :‘Read timed out
- MySQL 23 classic interviews hang the interviewer
- SimpleChannelInboundHandler使用总结
- Pagoda+FastAdmin 404 Not Found
- 【暑期每日一题】洛谷 P1551 亲戚
- [数据集][VOC]眼睛佩戴数据集VOC格式6000张
- GCC编译器技术解析
猜你喜欢
Vscode连接远程服务器出现‘Acquiring lock on/home/~’问题
ASP.NET Core Web API 幂等性
aTrust项目的相关操作与分享
optional
MySQL (3)
交换网络----三种生成树协议
[Dataset][VOC] Eyewear dataset 6000 in VOC format
CAT1 4G+Ethernet development board Tencent cloud mobile phone WeChat applet display temperature and delivery control
Nodejs installation and global configuration (super detailed)
System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security
随机推荐
See the picture to understand | How to choose sales indicators to measure the health of business growth
有人开源全凭“为爱发电”,有人却用开源“搞到了钱”
张驰课堂:六西格玛培训工具——箱线图
typescript 'props' is declared but its value is never read solution
Revitalize rural circular economy and digital chain to link agricultural "ecological chain"
交换--STP协议
Two good php debug tutorials
GCC编译器技术解析
PHP Warning: putenv() has been disabled for security reasons in phar
HCIP 第二天
Facebook社媒营销的5大技巧,迅速提高独立站转化率!
文件上传漏洞(二)
MySql - there is no insert, there is update or ignored
【暑期每日一题】洛谷 P1192 台阶问题
SphereEx苗立尧:云原生架构下的Database Mesh研发实践
解决Pytorch模型在Gunicorn部署无法运行或者超时问题
nacos源码启动找不到istio包
pointer arithmetic in c language
.NET Static Code Weaving - Rougamo Release 1.1.0
数据库概论之MySQL表的增删改查2