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);

  • 相关阅读:
    IntelliJ IDEA 如何在同一个窗口创建多个项目--超详细教程
    spring IOC原理
    java工作错误总结
    java跬步积累
    简单易懂设计模式——简单工厂模式
    Argo 项目入驻 CNCF,一文解析 Kubernetes 原生工作流
    电子书下载 | 超实用!阿里售后专家的 K8s 问题排查案例合集
    在生产环境中,阿里云如何构建高性能云原生容器网络?(含 PPT 下载)
    SIG Cloud Provider Alibaba 网研会第 2 期顺利召开 | 云原生生态周报 Vol. 46
    提问赠书 | 我们请了 7 位云原生专家,等你来问
  • 原文地址:https://www.cnblogs.com/kingwangzhen/p/1585559.html
Copyright © 2011-2022 走看看