Binding object to winForm controller through VS2010 Designer(通过VS2010设计器将对象绑定到winForm控件上)...

1. Create a Windows Form project from vs2010.

2. Add a class named “Student” with two public properties, Name(string) and Id(int).

3. Build project.

4. Add a DataSource to this project, you can use the option from Toolbar or just right click on this project and select add a item option.

5. Select “Object” in the “Choose a Data Source Type” in the “Data Source Configuration Wizard”.

image

6. Check the “Student” type which we add in to this project before.

image

7. After those steps, you will see “Student.datasource” in the “Properties->DataSources”.

Ok, now, our data source added to the project successfully.

8. Open the “Data Source” tab, you will see the Student data source is existing, then you just can drag it onto the Form, VS2010 will create a DataGridView with the “BindingNavigator”.

image

Now, we had finished to bind the Object to the DataGridView.

Then we will go on to bind the Object’s Property to a TextBox.

9. Open the “Formatting and Advanced Binding” window by click on the “…” button in the “(Advanced)” row.

Then choose a property for binding to the TextBox from “Binding” ComboBox.

For the Properties, you also can set it in the Properties tab.

image

Congratulations!

You have finished to learn how to use VS2010 designer to bind a object(and its property) to the winForm Controller.

Then you can run this application, add records to the DataGridView, you will see that the value in the TextBox also changed when you set some value to the match property.

The following is a view when the application is running.

bindingresult

You can download the whole demo project from my sky driver:

http://cid-bb789f72272d4858.photos.live.com/self.aspx/2011/2011Y03M/BindObjectToWinFormController.zip

FileDownload.aspx?ProjectName=1code&DownloadId=165659&Build=17601

PS:我的同事开发了一个MSDN论坛的小工具,有兴趣的朋友可以试试,此工具已开始在国内推行:

MSDN论坛好帮手

转载于:https://www.cnblogs.com/telnet_mike/archive/2011/03/16/1986360.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值