当前位置:网站首页>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会变化吗?
边栏推荐
- 实例032:反向输出II
- FaceBook社媒营销高效转化技巧分享
- punch day05
- Submit code process
- [npm install error report collection] - npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
- Wuhan 2022 organizing of the high-performance computing added new ecological development of high-performance computing
- 能与观众实时互动的Claper
- 张驰课堂:六西格玛测量系统的误差分析与判定
- GCC编译器技术解析
- 【npm install 报错问题合集】- npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
猜你喜欢

数据库概论-MySQL的数据表的基本操作

Specified URL is not reachable,caused by :‘Read timed out

“蔚来杯“2022牛客暑期多校训练营4,签到题NDKHL

Leetcode Weekly 304

2022.07.31(LC_6133_分组的最大数量)

APP special test: traffic test

堡垒机、堡垒机的原理

See the picture to understand | How to choose sales indicators to measure the health of business growth

每周推荐短视频:为什么产品开发需要数字化?如何做到数字化?

MySQL 5.7 installation tutorial (full-step, nanny-level tutorial)
随机推荐
MySQL classic 50 practice questions and the most detailed analysis of the whole network
“蔚来杯“2022牛客暑期多校训练营4,签到题NDKHL
第06章 索引的数据结构【2.索引及调优篇】【MySQL高级】
GCC编译器技术解析
The nacos source code can not find the istio package
[Dataset][VOC] Eyewear dataset 6000 in VOC format
分离轴定理SAT凸多边形精确碰撞检测
Xgboost报错ValueError:无效的形状:标签(1650 2)
实例032:反向输出II
In-depth analysis of the initialization of member variables and local variables
2022年7月18日-7月31日(Ue4视频教程和文档,20小时。合计1412小时,剩8588小时)
Go inside the basic knowledge
速看!PMP新考纲、PMBOK第七版解读
Specified URL is not reachable,caused by :‘Read timed out
DNS resolution process
有人开源全凭“为爱发电”,有人却用开源“搞到了钱”
Resolving C# non-static field, method or property "islandnum.Program.getIslandCount(int[][], int, int)" requires an object reference
[npm install error report collection] - npm ERR! code ENOTEMPTY npm ERR! syscall rmdir
打卡day05
MySQL 5.7 installation tutorial (full-step, nanny-level tutorial)