zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    tsm 存放磁带到带库
    tsm 切记
    添加路由时啥时候是dev啥时候是gw
    网卡上绑定多个IP地址
    更改本地环回地址引发的血案
    自学网络 arp_ignore/arp_announce
    do_try_to_free_pages
    如何用ssh实现端口的映射
    显示系统中所有的socket信息
    ifstat查看网络流量的原理
  • 原文地址:https://www.cnblogs.com/kingwangzhen/p/1585559.html
Copyright © 2011-2022 走看看