首页 > 代码库 > DataSet, BindingSource, BindingNavigator Relationship

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