当前位置: 首页 > news >正文

香河建设局网站前端开发培训机构怎么样

香河建设局网站,前端开发培训机构怎么样,net域名 著名网站,公关服务本文内容 简单绑定的更改通知基于列表的绑定的更改通知自定义控件的更改通知应用 PropertyNameChanged 模式实现 INotifyPropertyChanged 接口同步绑定 Windows 窗体数据绑定最重要的概念之一是更改通知。 为确保数据源和绑定控件始终具有最新数据#xff0c;必须为数据绑定…本文内容 简单绑定的更改通知基于列表的绑定的更改通知自定义控件的更改通知应用 PropertyNameChanged 模式实现 INotifyPropertyChanged 接口同步绑定 Windows 窗体数据绑定最重要的概念之一是更改通知。 为确保数据源和绑定控件始终具有最新数据必须为数据绑定添加更改通知。 具体来说你希望确保绑定控件在对其数据源进行更改时得到通知。 数据源在对控件的绑定属性进行更改时得到通知。 根据数据绑定的类型有不同类型的更改通知 简单绑定其中单个控件属性绑定到对象的单个实例。 基于列表的绑定它可以包括绑定到列表中项属性的单个控件属性或绑定到对象列表的控件属性。 此外如果正在创建要用于数据绑定的 Windows 窗体控件必须将 PropertyNameChanged 模式应用于控件。 将模式应用于控件后会将对控件的绑定属性的更改传播到数据源。 1、简单绑定的更改通知 对于简单绑定业务对象必须在绑定属性的值更改时提供更改通知。 可以通过为业务对象的每个属性公开一个 PropertyNameChanged 事件来提供更改通知。 同时需要使用 BindingSource 或首选方法将业务对象绑定到控件在该方法中业务对象实现 INotifyPropertyChanged 接口并在属性值更改时引发 PropertyChanged 事件。 使用实现 INotifyPropertyChanged 接口的对象时不必使用 BindingSource 将对象绑定到控件。 但建议使用 BindingSource。 2、基于列表的绑定的更改通知 Windows 窗体依靠绑定列表来向绑定控件提供提供属性更改和列表更改信息。 属性更改是更改列表项属性值列表更改是从列表中删除项或向列表添加项。 因此用于数据绑定的列表必须实现 IBindingList它提供两种类型的更改通知。 BindingListT 是 IBindingList 的通用实现旨在与 Windows 窗体数据绑定一起使用。 可以创建一个 BindingList其中包含实现 INotifyPropertyChanged 的​​业务对象类型并且该列表将自动将 PropertyChanged 事件转换为 ListChanged 事件。 如果绑定列表不是 IBindingList必须使用 BindingSource 组件将对象列表绑定到 Windows 窗体控件。 BindingSource 组件将提供属性到列表的转换该转换类似于 BindingList 的属性到列表的转换。  3、自定义控件的更改通知 最后在控件端必须为每个旨在绑定到数据的属性公开一个 PropertyNameChanged 事件。 然后将对控件属性的更改传播到绑定的数据源。  4、应用 PropertyNameChanged 模式 下面的代码示例演示如何将 PropertyNameChanged 模式应用于自定义控件。 在实现与 Windows 窗体数据绑定引擎一起使用的自定义控件时请应用该模式。 // This class implements a simple user control // that demonstrates how to apply the propertyNameChanged pattern. [ComplexBindingProperties(DataSource, DataMember)] public class CustomerControl : UserControl {private DataGridView dataGridView1;private Label label1;private DateTime lastUpdate DateTime.Now;public EventHandler DataSourceChanged;public object DataSource{get{return this.dataGridView1.DataSource;}set{if (DataSource ! value){this.dataGridView1.DataSource value;OnDataSourceChanged();}}}public string DataMember{get { return this.dataGridView1.DataMember; }set { this.dataGridView1.DataMember value; }}private void OnDataSourceChanged(){if (DataSourceChanged ! null){DataSourceChanged(this, new EventArgs());}}public CustomerControl(){this.dataGridView1 new System.Windows.Forms.DataGridView();this.label1 new System.Windows.Forms.Label();this.dataGridView1.ColumnHeadersHeightSizeMode System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;this.dataGridView1.ImeMode System.Windows.Forms.ImeMode.Disable;this.dataGridView1.Location new System.Drawing.Point(100, 100);this.dataGridView1.Size new System.Drawing.Size(500,500);this.dataGridView1.TabIndex 1;this.label1.AutoSize true;this.label1.Location new System.Drawing.Point(50, 50);this.label1.Name label1;this.label1.Size new System.Drawing.Size(76, 13);this.label1.TabIndex 2;this.label1.Text Customer List:;this.Controls.Add(this.label1);this.Controls.Add(this.dataGridView1);this.Size new System.Drawing.Size(450, 250);} }5、实现 INotifyPropertyChanged 接口 下面的代码示例演示如何实现 INotifyPropertyChanged 接口。 在 Windows 窗体数据绑定中使用的业务对象上实现该接口。 实现时该接口将业务对象上的属性更改与绑定控件进行通信。 using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Runtime.CompilerServices; using System.Windows.Forms;// Change the namespace to the project name. namespace binding_control_example {// This form demonstrates using a BindingSource to bind// a list to a DataGridView control. The list does not// raise change notifications. However the DemoCustomer1 type// in the list does.public partial class Form3 : Form{// This button causes the value of a list element to be changed.private Button changeItemBtn new Button();// This DataGridView control displays the contents of the list.private DataGridView customersDataGridView new DataGridView();// This BindingSource binds the list to the DataGridView control.private BindingSource customersBindingSource new BindingSource();public Form3(){InitializeComponent();// Set up the Change Item button.this.changeItemBtn.Text Change Item;this.changeItemBtn.Dock DockStyle.Bottom;this.changeItemBtn.Height 100;//this.changeItemBtn.Click // new EventHandler(changeItemBtn_Click);this.Controls.Add(this.changeItemBtn);// Set up the DataGridView.customersDataGridView.Dock DockStyle.Top;this.Controls.Add(customersDataGridView);this.Size new Size(400, 200);}private void Form3_Load(object sender, EventArgs e){this.Top 100;this.Left 100;this.Height 600;this.Width 1000;// Create and populate the list of DemoCustomer objects// which will supply data to the DataGridView.BindingListDemoCustomer1 customerList new ();customerList.Add(DemoCustomer1.CreateNewCustomer());customerList.Add(DemoCustomer1.CreateNewCustomer());customerList.Add(DemoCustomer1.CreateNewCustomer());// Bind the list to the BindingSource.this.customersBindingSource.DataSource customerList;// Attach the BindingSource to the DataGridView.this.customersDataGridView.DataSource this.customersBindingSource;}// Change the value of the CompanyName property for the first// item in the list when the Change Item button is clicked.void changeItemBtn_Click(object sender, EventArgs e){// Get a reference to the list from the BindingSource.BindingListDemoCustomer1? customerList this.customersBindingSource.DataSource as BindingListDemoCustomer1;// Change the value of the CompanyName property for the// first item in the list.customerList[0].CustomerName Tailspin Toys;customerList[0].PhoneNumber (708)555-0150;}}// This is a simple customer class that// implements the IPropertyChange interface.public class DemoCustomer1 : INotifyPropertyChanged{// These fields hold the values for the public properties.private Guid idValue Guid.NewGuid();private string customerNameValue String.Empty;private string phoneNumberValue String.Empty;public event PropertyChangedEventHandler PropertyChanged;// This method is called by the Set accessor of each property.// The CallerMemberName attribute that is applied to the optional propertyName// parameter causes the property name of the caller to be substituted as an argument.private void NotifyPropertyChanged([CallerMemberName] String propertyName ){if (PropertyChanged ! null){PropertyChanged(this, new PropertyChangedEventArgs(propertyName));}}// The constructor is private to enforce the factory pattern.private DemoCustomer1(){customerNameValue Customer;phoneNumberValue (312)555-0100;}// This is the public factory method.public static DemoCustomer1 CreateNewCustomer(){return new DemoCustomer1();}// This property represents an ID, suitable// for use as a primary key in a database.public Guid ID{get{return this.idValue;}}public string CustomerName{get{return this.customerNameValue;}set{if (value ! this.customerNameValue){this.customerNameValue value;NotifyPropertyChanged();}}}public string PhoneNumber{get{return this.phoneNumberValue;}set{if (value ! this.phoneNumberValue){this.phoneNumberValue value;NotifyPropertyChanged();}}}} }6、同步绑定 在 Windows 窗体中实现数据绑定期间多个控件会绑定到同一数据源。 在某些情况下可能需要采取额外的步骤来确保控件的绑定属性之间以及它们和数据源之间保持同步。 在两种情况下需要执行以下步骤 数据源未实现 IBindingList因此生成类型为 ItemChanged 的 ListChanged 事件。 数据源实现了 IEditableObject。 在前一种情况下请使用 BindingSource 将数据源绑定到控件。 在后一种情况下请使用 BindingSource 并处理 BindingComplete 事件然后在相关的 BindingManagerBase 上调用 EndCurrentEdit。
http://www.zqtcl.cn/news/371440/

相关文章:

  • 米拓建站最新进展注册做网站的公司有哪些
  • 设计网站设计wordpress 改系统
  • 学校网站建设评审会议通知网站是怎么赢利的
  • 手机网站建设 苏州优化网站哪个好
  • 网站建设流程方案通州网站建设公司
  • 免费的十大免费货源网站全国领先网站制作
  • 农业网站建设方案 ppt中国有什么网站做跨境零售
  • 网站文章结构变更怎么做301如何自己制作自己的网站
  • 网站网站平台建设方案免费制作桥架app
  • 杭州网站界面设计招网站建设销售
  • 网站开发 流程图广州优化seo
  • 夫妻工作室网站建设品牌建设的内容
  • php搭建网站后台建设银行网站如何修改账单地址
  • 网站域名查询系统关键词语有哪些
  • 专业金融网站建设wordpress匿名投稿
  • 生产做网站表带的制造厂家百度文库个人登录
  • 丰都网站建设费用成都品牌包装设计
  • 建设项目安监备案网站免费学生网页制作成品代码
  • wordpress默认登陆地址修改廊坊百度关键词优化怎么做
  • 免费下载策划书的网站外贸网站 域名后缀
  • 网站导航条做信息网站需要什么
  • 网站推广朋友圈文案嵩县网站建设
  • 网站建设实践考试试题app运营推广策划方案
  • django网站开发源码阿里邮箱登录
  • 机床网站建设网站关键词优化怎么做
  • 全网营销一站式推广wordpress新文章加new
  • 做网站哪个系统最安全长沙简界网络科技有限公司
  • 象山县城乡和住房建设局网站上海公司牌照最新价格
  • 复旦学霸张立勇做的网站开一个公司需要多少钱
  • 专业建设公司网站软件技术培训