C#:Winform控件绑定数据

目录

简介

绑定基类

功能扩展

简单控件绑定

列表控件绑定

绑定BindingList集合

绑定DataTable表格

绑定BindingSource源

表格控件绑定

绑定DataTable

绑定BindingList

UI线程全局类


简介

在C#中提起控件绑定数据,大部分人首先想到的是WPF,其实Winform也支持控件和数据的绑定。

Winform中的数据绑定按控件类型可以分为以下几种:

  • 简单控件绑定
  • 列表控件绑定
  • 表格控件绑定

绑定基类

绑定数据类必须实现INotifyPropertyChanged接口,否则数据类属性的变更无法实时刷新到界面,但可以从界面刷新到类。
为了方便,我们设计一个绑定基类:

/// 
/// 数据绑定基类
/// 
public abstract class BindableBase : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    protected bool SetProperty(ref T field, T newValue, [CallerMemberName] string propertyName = null)
    {
        if (!EqualityComparer.Default.Equals(field, newValue))
        {
            field = newValue;
        

你可能感兴趣的:(typescript,javascript,前端)