当前位置:网站首页>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会变化吗?
边栏推荐
- 专家见解|经济低迷期把握创新机会的 3 大方法
- HCIP 第一天
- 数据库概论之MySQL表的增删改查1
- “蔚来杯“2022牛客暑期多校训练营5,签到题KBGHFCD
- Kind of weird!Access the destination URL, the host can container but not
- 【暑期每日一题】洛谷 P3156 【深基15.例1】询问学号
- 张驰课堂:六西格玛测量系统的误差分析与判定
- 实例027:递归输出
- .NET Static Code Weaving - Rougamo Release 1.1.0
- MySQL 5.7 installation tutorial (full-step, nanny-level tutorial)
猜你喜欢

速看!PMP新考纲、PMBOK第七版解读

APP special test: traffic test

MySQL Advanced SQL Statements (2)

MySQL high-level --- storage engine, index, lock

实验8 VLAN综合实验

Leetcode Weekly 304

Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing

2022夏暑假每日一题(六)

Nodejs installation and global configuration (super detailed)

CAT1 4G+Ethernet development board Tencent cloud mobile phone WeChat applet display temperature and delivery control
随机推荐
Facebook社媒营销的5大技巧,迅速提高独立站转化率!
request.getSession(),的故事
解决Pytorch模型在Gunicorn部署无法运行或者超时问题
振兴农村循环经济 和数链串起农业“生态链”
(笔记整理未完成)【图论】图的遍历
技术管理三级跳
CAT1 4G+Ethernet development board Tencent cloud mobile phone WeChat applet display temperature and delivery control
武汉高性能计算大会2022举办,高性能计算生态发展再添新动力
PMP新考纲通关秘籍,告别抓瞎
享年94岁,图灵奖得主、计算复杂性理论先驱Juris Hartmanis逝世
2022夏暑假每日一题(六)
交换部分 VLAN
[npm install error report collection] - npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
ASP.NET Core Web API 幂等性
aTrust项目的相关操作与分享
交换网络----三种生成树协议
【论文精读】Geometric Structure Preserving Warp for Natural Image Stitching
C# FileInfo class
Two good php debug tutorials
punch day05