首页 > 代码库 > 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"));
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"); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。