当前位置: 首页>>代码示例>>C#>>正文


C# DataView.AddNew方法代码示例

本文整理汇总了C#中DataView.AddNew方法的典型用法代码示例。如果您正苦于以下问题:C# DataView.AddNew方法的具体用法?C# DataView.AddNew怎么用?C# DataView.AddNew使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataView的用法示例。


在下文中一共展示了DataView.AddNew方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddNew

        public void AddNew()
        {
            //create the source datatable
            DataTable dt = DataProvider.CreateChildDataTable();

            //create the dataview for the table
            DataView dv = new DataView(dt);

            int CountView = dv.Count;
            int CountTable = dt.Rows.Count;

            DataRowView drv = null;

            // AddNew - DataView Row Count
            drv = dv.AddNew();
            Assert.Equal(dv.Count, CountView + 1);

            // AddNew - Table Row Count 
            Assert.Equal(dt.Rows.Count, CountTable);

            // AddNew - new row in DataTable
            drv.EndEdit();
            Assert.Equal(dt.Rows.Count, CountTable + 1);

            // AddNew - new row != null
            Assert.Equal(true, drv != null);

            // AddNew - check table
            Assert.Equal(dt, drv.Row.Table);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:30,代码来源:DataViewTest2.cs

示例2: IsNew

        public void IsNew()
        {
            DataTable dt = DataProvider.CreateParentDataTable();
            DataView dv = new DataView(dt);

            DataRowView drv = dv[0];

            // existing row
            Assert.Equal(false, drv.IsNew);

            // add new row
            drv = dv.AddNew();
            Assert.Equal(true, drv.IsNew);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:14,代码来源:DataRowViewTest2.cs

示例3: RowVersion1

 public void RowVersion1()
 {
     // I guess we could write better tests.
     DataTable dt = new DataTable("table");
     dt.Columns.Add("col");
     dt.Rows.Add(new object[] { 1 });
     DataView dv = new DataView(dt);
     DataRowView drv = dv.AddNew();
     Assert.Equal(DataRowVersion.Current, drv.RowVersion);
     Assert.Equal(DataRowVersion.Current, dv[0].RowVersion);
     drv["col"] = "mod";
     Assert.Equal(DataRowVersion.Current, drv.RowVersion);
     Assert.Equal(DataRowVersion.Current, dv[0].RowVersion);
     dt.AcceptChanges();
     Assert.Equal(DataRowVersion.Current, drv.RowVersion);
     Assert.Equal(DataRowVersion.Current, dv[0].RowVersion);
     drv.EndEdit();
     dv[0].EndEdit();
     Assert.Equal(DataRowVersion.Current, drv.RowVersion);
     Assert.Equal(DataRowVersion.Current, dv[0].RowVersion);
 }
开发者ID:dotnet,项目名称:corefx,代码行数:21,代码来源:DataRowViewTest.cs

示例4: ItemException

 public void ItemException()
 {
     Assert.Throws<RowNotInTableException>(() =>
    {
        DataTable dt = new DataTable("table");
        dt.Columns.Add("col");
        dt.Rows.Add((new object[] { "val" }));
        DataView dv = new DataView(dt);
        DataRowView drv = dv.AddNew();
        drv.Row["col"] = "test";
        drv.Row.CancelEdit();
        object o = drv["col"];
    });
 }
开发者ID:dotnet,项目名称:corefx,代码行数:14,代码来源:DataRowViewTest.cs

示例5: IsEdit

        public void IsEdit()
        {
            DataTable dt = new DataTable("table");
            dt.Columns.Add("col");
            dt.Rows.Add((new object[] { "val" }));

            DataView dv = new DataView(dt);
            DataRowView drv = dv[0];
            dt.Rows[0].BeginEdit();
            Assert.Equal(true, drv.IsEdit);

            drv = dv.AddNew();
            drv.Row["col"] = "test";
            drv.Row.CancelEdit();
            Assert.Equal(false, drv.IsEdit);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:16,代码来源:DataRowViewTest.cs

示例6: ListChanged

        public void ListChanged()
        {
            DataTable dt = DataProvider.CreateParentDataTable();
            DataView dv = new DataView(dt);

            //add event handler
            dv.ListChanged += new ListChangedEventHandler(dv_ListChanged);

            // ----- Change Value ---------
            _evProp = null;
            // change value - Event raised
            dv[1]["String1"] = "something";
            Assert.Equal(true, _evProp != null);
            // change value - ListChangedType
            Assert.Equal(ListChangedType.ItemChanged, _evProp.lstType);
            // change value - NewIndex
            Assert.Equal(1, _evProp.NewIndex);
            // change value - OldIndex
            Assert.Equal(1, _evProp.OldIndex);

            // ----- Add New ---------
            _evProp = null;
            // Add New  - Event raised
            dv.AddNew();
            Assert.Equal(true, _evProp != null);
            // Add New  - ListChangedType
            Assert.Equal(ListChangedType.ItemAdded, _evProp.lstType);
            // Add New  - NewIndex
            Assert.Equal(6, _evProp.NewIndex);
            // Add New  - OldIndex
            Assert.Equal(-1, _evProp.OldIndex);

            // ----- Sort ---------
            _evProp = null;
            // sort  - Event raised
            dv.Sort = "ParentId Desc";
            Assert.Equal(true, _evProp != null);
            // sort - ListChangedType
            Assert.Equal(ListChangedType.Reset, _evProp.lstType);
            // sort - NewIndex
            Assert.Equal(-1, _evProp.NewIndex);
            // sort - OldIndex
            Assert.Equal(-1, _evProp.OldIndex);

            //ListChangedType - this was not checked
            //Move
            //PropertyDescriptorAdded - A PropertyDescriptor was added, which changed the schema. 
            //PropertyDescriptorChanged - A PropertyDescriptor was changed, which changed the schema. 
            //PropertyDescriptorDeleted 
        }
开发者ID:dotnet,项目名称:corefx,代码行数:50,代码来源:DataViewTest2.cs

示例7: AllowNew

        public void AllowNew()
        {
            DataTable dt = DataProvider.CreateParentDataTable();
            DataView dv = new DataView(dt);

            // AllowNew - default value
            Assert.Equal(true, dv.AllowNew);

            // AllowNew - true
            dv.AllowNew = true;
            Assert.Equal(true, dv.AllowNew);

            // AllowNew - false
            dv.AllowNew = false;
            Assert.Equal(false, dv.AllowNew);

            // AllowNew - exception
            Assert.Throws<DataException>(() =>
            {
                dv.AddNew();
            });

            dv.AllowNew = true;
            int RowsCount = dv.Count;

            // AllowNew - exception
            dv.AddNew();
            Assert.Equal(RowsCount + 1, dv.Count);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:29,代码来源:DataViewTest2.cs

示例8: CancelEditAndEvents

        public void CancelEditAndEvents()
        {
            string reference = " =====ItemAdded:3 ------4 =====ItemAdded:3 =====ItemAdded:4 ------5 =====ItemAdded:4 =====ItemAdded:5 ------6 =====ItemDeleted:5 ------5 =====ItemAdded:5";

            _eventWriter = new StringWriter();

            DataTable dt = new DataTable();
            dt.Columns.Add("col1");
            dt.Columns.Add("col2");
            dt.Columns.Add("col3");
            dt.Rows.Add(new object[] { 1, 2, 3 });
            dt.Rows.Add(new object[] { 1, 2, 3 });
            dt.Rows.Add(new object[] { 1, 2, 3 });

            DataView dv = new DataView(dt);
            dv.ListChanged += new ListChangedEventHandler(ListChanged);
            DataRowView a1 = dv.AddNew();
            _eventWriter.Write(" ------" + dv.Count);
            // I wonder why but MS fires another event here.
            a1 = dv.AddNew();
            _eventWriter.Write(" ------" + dv.Count);
            // I wonder why but MS fires another event here.
            DataRowView a2 = dv.AddNew();
            _eventWriter.Write(" ------" + dv.Count);
            a2.CancelEdit();
            _eventWriter.Write(" ------" + dv.Count);
            DataRowView a3 = dv.AddNew();

            Assert.Equal(reference, _eventWriter.ToString());
        }
开发者ID:ericeil,项目名称:corefx,代码行数:30,代码来源:DataViewTest.cs

示例9: Bug18898

        public void Bug18898()
        {
            var table = new DataTable();
            table.Columns.Add("col1");
            table.Columns.Add("col2");

            table.Rows.Add("1", "2");
            table.Rows.Add("4", "3");

            table.AcceptChanges();

            table.Rows.Add("5", "6");

            DataView dv = new DataView(table, string.Empty, string.Empty, DataViewRowState.Added);
            dv.AllowNew = true;
            var new_row = dv.AddNew();
            new_row[0] = "7";
            new_row[1] = "8";

            var another_new_row = dv.AddNew();
            another_new_row[0] = "9";
            another_new_row[1] = "10";

            Assert.Equal(dv[2][0], "9");

            //This should not throw a System.Data.VersionNotFoundException: "There is no Proposed data to accces"
            Assert.Equal(dv[1][0], "7");
        }
开发者ID:ericeil,项目名称:corefx,代码行数:28,代码来源:DataViewTest.cs


注:本文中的DataView.AddNew方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。