• WinForm TextBox数据绑定


     
            private DataTable dtStore;
            
    private System.Windows.Forms.TextBox txtID;
            
    private System.Windows.Forms.TextBox txtName;
            
    private System.Windows.Forms.BindingManagerBase BindingDataManager;
            
    private void frmDemo_Load(object sender, System.EventArgs e)
            
    {
                initForm();
            }

            
    private void btnFirst_Click(object sender, System.EventArgs e)
            
    {
                BindingDataManager.Position 
    = 0;
            }


            
    private void btnPre_Click(object sender, System.EventArgs e)
            
    {
                BindingDataManager.Position 
    -= 1;
            }


            
    private void btnNext_Click(object sender, System.EventArgs e)
            
    {
                BindingDataManager.Position 
    += 1;
            }


            
    private void btnLast_Click(object sender, System.EventArgs e)
            
    {
                BindingDataManager.Position 
    = BindingDataManager.Count -1;
            }

            
    private void initForm()
            
    {
                
    string strConn = @"Server=(local)\NETSDK;User id=sa;Pwd=sa;Database=Northwind";
                StringBuilder sbSQL 
    = new StringBuilder();
                sbSQL.Append(
    "select EmployeeID, FirstName + ' ' + LastName as EmployeeName ");
                sbSQL.Append(
    "from Employees");

                SqlDataAdapter da 
    = new SqlDataAdapter( sbSQL.ToString(), conn );

                dtStore 
    = new DataTable();
            
                da.Fill( dtStore );    
                
                txtID.DataBindings.Clear();
                txtName.DataBindings.Clear();

                txtID.DataBindings.Add( 
    "Text", dtStore, dtStore.Columns[0].ColumnName );
                txtName.DataBindings.Add( 
    "Text", dtStore, dtStore.Columns[1].ColumnName );

                BindingDataManager 
    = this.BindingContext[ dtStore ];
            }

    BindingManagerBase是对Windows 窗体上绑定到相同数据源的数据绑定控件进行同步的

    =======================================================================

      DataSet ds = DataRepository.UsersProvider.GetAll().ToDataSet(true);
                BindingSource bs = new BindingSource();
                bs.DataSource = ds.Tables[0];

               bindingNavigator1.BindingSource = bs;            
               dataGridView1.DataSource = bs;
               textBox1.DataBindings.Add("Text", bs, ds.Tables[0].Columns[0].ColumnName);
               textBox2.DataBindings.Add("Text",bs, ds.Tables[0].Columns[1].ColumnName);

  • 相关阅读:
    第十七章 Mnesia: Erlang数据库
    第十六章 OTP概述
    第十五章 ETS和DETS:大数据的存储机制
    第十四章 套接字编程
    第十三章 对文件编程
    nginx启动、关闭、重启及常用的命令
    《山海经》异兽75种,附图
    Spring中Configuration的理解
    Spring Boot学习一之Spring Beans和依赖注入
    Spring Boot学习一之配置类及自动配置
  • 原文地址:https://www.cnblogs.com/kingwangzhen/p/1585559.html
Copyright © 2020-2023  润新知