DataBinder类详解 | Winform MiniFramework蝇量框架|C/S开发框架
作者:csframework|C/S框架网  发布日期:2022/02/23 16:38:08

DataBinder类详解 | Winform MiniFramework蝇量框架|C/S开发框架

DataBinder类详解 - Winform MiniFramework蝇量框架

一、DataBinder类

DataBinder类提供一组通用方法,用于绑定数据输入组件的数据源、下拉组件的参考数据源,支持以下组件:

  • 文本框(BaseEdit、TextEdit、ButtonEdit)
  • 下拉框(ComboBox、LookupEdit)
  • 列表(CheckedListBoxControl、CheckedComboBoxEdit)
  • 复选框(CheckEdit)
  • 参考组件(LookupEdit)
  • 图片组件(PictureEdit)

二、DataBinder类优势

根据界面数据输入组件的需求,定义一组通用方法自动绑定数据源,而不需要针对每个组件重复设置属性。

比如:LookupEdit组件,需要设计下拉窗体中显示的列,而通过 DataBinder 类的 BoundUser 方法,统一定义列的属性,比如标题名称、列宽度等:

C# 全选
        public static void BoundUser(LookUpEdit lue)
        {
            lue.Properties.NullText = "";
            lue.Properties.DropDownRows = 10;
            InitializeControl(lue, new string[] { "帐号", "姓名" }, new string[] { "Account", "UserName" });
            lue.Properties.Columns[0].Width = 60;
            lue.Properties.Columns[1].Width = 140;
            lue.Properties.PopupWidth = 200;
            DataBinder.BindingLookupEditDataSource(lue, DataDictCache.Cache.User, "UserName", "Account");
        }

三、BindingControl

用于绑定单个文本输入组件的数据源。规则:txt+字段名,或者chk+字段名,其它类型可以扩展。

C# 全选
     public static void BindingControl(Control ctl, object dataSource, string bindField, string propertyName)
        {
            try
            {
                ctl.DataBindings.Clear();
                Binding b = new Binding(propertyName, dataSource, bindField);
                ctl.DataBindings.Add(b);
            }
            catch (Exception ex)
            {
                Msg.ShowException(ex);
            }
        }

四、BindingEditorPanel

用于绑定数据编辑区域(Panel 组件作为容器)所有文本输入组件的数据源。规则:txt+字段名,或者chk+字段名,其它类型可以扩展。

循环枚举 Panel 容器內所有以txt开头的组件,逐个绑定数据源:

C# 全选
 public static void BindingEditorPanel(Control editorPanel, DataTable dataSource)
{
}

五、使用方法

5.1 绑定下拉组件的数据源

//绑定用户资料的下拉数据源
DataBinder.BoundUser(txtUserId);

5.1 绑定数据编辑区域所有组件的数据源

DataBinder类详解 | Winform MiniFramework蝇量框架|C/S开发框架

C# 全选
        //绑定所有文本框的数据源
        private void DoBindingSummaryEditor(DataTable summary)
        {
            DataBinder.BindingEditorPanel(gcDetailEditor, summary);
            
            //独立绑定其他自定义组件的数据源
            DataBinder.BindingControl(ucCusAttributes, summary, tb_Customer.AttributeCodes, "EditValue");
        }

DataBinder类详解 | Winform MiniFramework蝇量框架|C/S开发框架

C/S框架网|原创精神.创造价值.打造精品



扫一扫加作者微信
C/S框架网作者微信 C/S框架网|原创作品.质量保障.竭诚为您服务
上一篇 下一篇