System.Data.DataView.AddNew C# (CSharp) Метод

AddNew() публичный Метод

public AddNew ( ) : DataRowView
Результат DataRowView
		public virtual DataRowView AddNew ()
		{
			if (!IsOpen)
				throw new DataException ("DataView is not open.");
			if (!AllowNew)
				throw new DataException ("Cannot call AddNew on a DataView where AllowNew is false.");

			if (_lastAdded != null)
				// FIXME : finish last added
				CompleteLastAdded (true);

			_lastAdded = dataTable.NewRow ();
			UpdateIndex (true);
			OnListChanged (new ListChangedEventArgs (ListChangedType.ItemAdded, Count - 1, -1));

			return this [Count - 1];
		}

Usage Example

Пример #1
0
		[Test] 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.AreEqual(dv.Count , CountView+1, "DV1");

			// AddNew - Table Row Count 
			Assert.AreEqual(dt.Rows.Count , CountTable, "DV2");

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

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

			// AddNew - check table
			Assert.AreEqual(dt, drv.Row.Table, "DV5");
		}
All Usage Examples Of System.Data.DataView::AddNew