zoukankan      html  css  js  c++  java
  • DataGridView绑定DataTable的正确姿势

    1. 将DataTable 绑定到BindingSource

    2. 将BindingSource绑定到DataGridView

    3. DataGridView修改完要从Datatable取值时,同步过去时,BindingSource和DataGridView两个都要执行EndEdit()

    例程:

     public partial class Form1 : Form
        {
            DataTable mTable = new DataTable();
            BindingSource mbs = new BindingSource();
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                mTable.Columns.Add("Name",typeof(string));
                mTable.Columns.Add("Age", typeof(float));
                mTable.Columns.Add("Dept", typeof(string));
                mTable.Columns.Add("IsDeleted", typeof(bool));
                mTable.Rows.Add("Jack", 21, "C1", false);
                mTable.Rows.Add("Rose", 21, "C2", false);
                mTable.Rows.Add("Tom", 21, "C1", false);
                mTable.Rows.Add("Micky", 21, "C1", false);
                mTable.Rows.Add("Steven Chou", 21, "C1", false);
                mbs.DataSource = mTable;
                grd.DataSource = mbs;
            }
    
            private void BtnDel_Click(object sender, EventArgs e)
            {
                mTable.Rows.Remove(mTable.Rows[grd.CurrentRow.Index]);
            }
    
            private void BtnSave_Click(object sender, EventArgs e)
            {
                grd.EndEdit();
                mbs.EndEdit();
    
                int N = mTable.Rows.Count;
                
            }
        }
  • 相关阅读:
    sqlnet设置网络传输加密
    临时表处理办法
    分布式事务2PC_PENDING异常处理
    统计信息收集百分比和并行改变
    dataguard丢失归档日志处理
    patch 28729262
    Cardinality
    统计信息不准导致sql性能下降
    子查询展开
    ogg 单表拆分合并进程
  • 原文地址:https://www.cnblogs.com/ccjungle/p/11308195.html
Copyright © 2011-2022 走看看