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

小灰灰 2021-12-09 04:43 118阅读 0赞
  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

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

image

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

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

  1. 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.

  1. 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

发表评论

表情:
评论列表 (有 0 条评论,118人围观)

还没有评论,来说两句吧...

相关阅读

    相关 VS2010下开发ActiveX

    [初试ActiveX控件][ActiveX]     这几天看了关于COM技术的资料并看了孙鑫老师关于ActiveX控件的教程,自己就动手实践了一下。教程中用的是VC6.0实

    相关 VS2010通过OLE操作Excel2010

    我使用的语言是C++,网上有许多这方面的例子,但由于VS与Office版本的问题,都需要一些调整,下面是我在使用时遇到的一些问题集解决方法: 操作步骤: a. projec