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