zoukankan      html  css  js  c++  java
  • DataSet, BindingSource, BindingNavigator Relationship

    Multiple Bindings caused dataBing weird???? 

    Text.DataBindings.Add(new Binding("Text", bs1, "Index_Code"));

    Text.DataBindings.Add(new Binding("Text", bs2, "Index_Code"));

            BindingSource bs = new BindingSource();
            DataTable table = new DataTable();
    
    
    
                table.Columns.Add("Name", typeof(string));
                table.Columns.Add("Value", typeof(int));
    
                table.Rows.Add("A", 1);
                table.Rows.Add("B", 2);
    
                //comboBox1.DataSource = table;
                //comboBox1.DisplayMember = "Name";
                //comboBox1.ValueMember = "Value";
                ////comboBox1.DataBindings.Add();
                //comboBox1.SelectedIndex = -1;
    
                bs = new BindingSource();
                bs.DataSource = table;
                bindingNavigator1.BindingSource = bs;
    
                textBox1.DataBindings.Add(new Binding("Text", bs, "Name"));                
    View Code
    private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
            {
    
                DataRowView row = (DataRowView)bs.Current;
    
                row["Name"] = "C";
                row["Value"] = 3;
    
                //row.IsNew is true;
    
                int i = table.Rows.Count;  // = 2
                bs.EndEdit(); //commit to datatable => dataSource get updated
                i = table.Rows.Count; // = 3
    
                if (row.IsNew) //false
                {
                    MessageBox.Show("new row");
                }
            }
    View Code
  • 相关阅读:
    集合
    16
    最常使用Eclipse快捷键
    Java小菜的进阶之路(异常捕获与处理(一))
    0803作业
    0801作业
    java中this与super的见解
    7.27作业
    7.23作业
    java内部类的浅谈(错误之处还请见谅!)
  • 原文地址:https://www.cnblogs.com/kevinygq/p/3895731.html
Copyright © 2011-2022 走看看