码迷,mamicode.com
首页 > 其他好文 > 详细

DataSet, BindingSource, BindingNavigator Relationship

时间:2014-08-06 22:44:22      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   art   ar   

Multiple Bindings caused dataBing weird???? 

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

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

 

bubuko.com,布布扣
        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

 

bubuko.com,布布扣
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

 

DataSet, BindingSource, BindingNavigator Relationship,布布扣,bubuko.com

DataSet, BindingSource, BindingNavigator Relationship

标签:style   blog   http   color   os   io   art   ar   

原文地址:http://www.cnblogs.com/kevinygq/p/3895731.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!