当前位置:网站首页>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会变化吗?
边栏推荐
- [数据集][VOC]男女数据集voc格式6188张
- In-depth analysis of the initialization of member variables and local variables
- July 18-July 31, 2022 (Ue4 video tutorials and documentation, 20 hours. Total 1412 hours, 8588 hours left)
- Detailed explanation of 9 common reasons for MySQL index failure
- 专家见解|经济低迷期把握创新机会的 3 大方法
- 技术管理三级跳
- 每周推荐短视频:为什么产品开发需要数字化?如何做到数字化?
- System.Security.SecurityException: 未找到源,但未能搜索某些或全部事件日志。不可 访问的日志: Security
- See the picture to understand | How to choose sales indicators to measure the health of business growth
- Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
猜你喜欢
振兴农村循环经济 和数链串起农业“生态链”
享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世
HCIP 第四天
typescript ‘props‘ is declared but its value is never read 解决办法
CAT1 4G+Ethernet development board Tencent cloud mobile phone WeChat applet display temperature and delivery control
abaqus如何快速导入其他cae文件的assembly?
APP special test: traffic test
Specified URL is not reachable,caused by :‘Read timed out
数据库概论-MySQL的数据表的基本操作
8/1 思维+扩展欧几里得+树上dp
随机推荐
ue先视频教程后深入
【npm install 报错问题合集】- npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
提交代码流程
MySQL high-level statements (1)
实验8 VLAN综合实验
Pagoda+FastAdmin 404 Not Found
Toolbox App 1.25 New Features at a Glance | Version Update
实例032:反向输出II
[npm install error report collection] - npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
MySQL 5.7 installation tutorial (full-step, nanny-level tutorial)
封装class类一次性解决全屏问题
2022年7月18日-7月31日(Ue4视频教程和文档,20小时。合计1412小时,剩8588小时)
交换部分 VLAN
笔记本开机黑屏提示:ERROR 0199:System Security-Security password retry count exceeded
MySQL Advanced Statements (1)
Connection reset by peer problem analysis
CAT1 4G+以太网开发板腾讯云手机微信小程序显示温度和下发控制
August 2022 plan, focusing on ue4 video tutorials
实例029:反向输出
Specified URL is not reachable,caused by :‘Read timed out