バージョン

Add() メソッド

新しい行をコレクションに追加します。
シンタックス
'宣言
 
Public Overloads Function Add() As UltraDataRow
public UltraDataRow Add()

戻り値の型

コレクションに追加された新しい行を返します。
使用例
Imports Infragistics.Shared
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinDataSource


    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles button1.Click
        Dim ds As UltraDataSource = New UltraDataSource()

        Dim col1 As UltraDataColumn = ds.Band.Columns.Add("ID", GetType(Integer))
        Dim col2 As UltraDataColumn = ds.Band.Columns.Add("Col2", GetType(String))

        Dim row As UltraDataRow
        Dim i As Integer
        For i = 0 To 5 - 1
            ' Look below where we call the Insert method for explanation on 
            ' what raiseAddEvents parameter does.
            row = ds.Rows.Add(True, New Object() {i, "Val " & i})
        Next

        ' Insert a row at index 0. A new row will be created and added to the
        ' collection at the specified index. RaiseAddEvents parameter of Add and
        ' Insert methods indicates whether the UltraDataSource should raise it's
        ' own RowAdding and RowAdded events. It does not indicate whether
        ' IBindingList.ListChanged event is raised or not.
        ' IBindingList.ListChanged event will always be raised regardless of the
        ' value of this parameter. This is useful when you have some logic in
        ' those event handlers for initializing new rows and you want that logic
        ' to be executed for the new row that you are inserting. If you use the
        ' overloads of Add or Insert that do not take raiseAddEvents parameter
        ' then add events won't be raised.
        row = ds.Rows.Insert(0, False, New Object() {-1, "Val -1"})

        ' Remove the inserted row. RaiseDeleteEvents parameter is analogous to
        ' the raiseAddEvents parameter of the Add and Insert methods. Look above
        ' where we call Insert for an explanation.
        row.ParentCollection.Remove(row, False)

        ' To check if a row is in a collection, use the Contains method.
        ' Following should print out false since the row has been deleted.
        Debug.WriteLine("Is deleted row in collection ? " & row.ParentCollection.Contains(row))

        ' A deleted row will have the index of -1. Following should print out -1
        ' since the row is not in the collection anymore. Row's Index property
        ' and IndexOf methods give the same results.
        Debug.WriteLine("Deleted row's index is " & row.Index)
        Debug.WriteLine("Deleted row's index is " & row.ParentCollection.IndexOf(row))

        ' You can also use the RemoveAt method to remove a row by specifying the 
        ' index of the row instead of the row itself.
        ds.Rows.RemoveAt(0, False)

        ' Print out the row count. This should print 4 as the row count since we
        ' added 5 using Add method in the for loop above and then added one
        ' using the Insert method above and then removed two using Remove and
        ' RemoveAt methods each.
        Debug.WriteLine("Row count = " & ds.Rows.Count)

        ' You can remove all rows from a row collection using Clear method. This
        ' is more efficient than deleting individual rows using Remove or
        ' RemoveAt methods.
        ds.Rows.Clear()

        ' You can use the SetCount method to add multiple rows at once. This can
        ' be more efficient than adding individual rows using Add method when
        ' adding a lot of rows.
        ds.Rows.SetCount(5)

        ' Add another 5 rows by setting the count to 10. Previously we added 5
        ' rows when we called SetCount( 5 ) above. Calling SetCount with 10 will
        ' add another 5 rows so that the new count becomes 10.
        ds.Rows.SetCount(10)

        ' Following line should print out 10.
        Debug.WriteLine("Row count = " & ds.Rows.Count)

        ds.Rows.SetCount(100000)

        ' Following line should print out 100000.
        Debug.WriteLine("Row count = " & ds.Rows.Count)
    End Sub
using Infragistics.Shared;
using Infragistics.Win;
using Infragistics.Win.UltraWinDataSource;
using System.Diagnostics;


		private void button1_Click(object sender, System.EventArgs e)
		{
			UltraDataSource ds = new UltraDataSource( );

			UltraDataColumn col1 = ds.Band.Columns.Add( "ID", typeof( int ) );
			UltraDataColumn col2 = ds.Band.Columns.Add( "Col2", typeof( string ) );

			UltraDataRow row;
			for ( int i = 0; i < 5; i++ )
			{
				// Look below where we call the Insert method for explanation on 
				// what raiseAddEvents parameter does.
				row = ds.Rows.Add( true, new object[] { i, "Val " + i } );
			}

			// Insert a row at index 0. A new row will be created and added to the
			// collection at the specified index. RaiseAddEvents parameter of Add and
			// Insert methods indicates whether the UltraDataSource should raise it's
			// own RowAdding and RowAdded events. It does not indicate whether
			// IBindingList.ListChanged event is raised or not.
			// IBindingList.ListChanged event will always be raised regardless of the
			// value of this parameter. This is useful when you have some logic in
			// those event handlers for initializing new rows and you want that logic
			// to be executed for the new row that you are inserting. If you use the
			// overloads of Add or Insert that do not take raiseAddEvents parameter
			// then add events won't be raised.
			row = ds.Rows.Insert( 0, false, new object[] { -1, "Val -1" } );

			// Remove the inserted row. RaiseDeleteEvents parameter is analogous to
			// the raiseAddEvents parameter of the Add and Insert methods. Look above
			// where we call Insert for an explanation.
			row.ParentCollection.Remove( row, false );

			// To check if a row is in a collection, use the Contains method.
			// Following should print out false since the row has been deleted.
			Debug.WriteLine( "Is deleted row in collection ? " + row.ParentCollection.Contains( row ) );

			// A deleted row will have the index of -1. Following should print out -1
			// since the row is not in the collection anymore. Row's Index property
			// and IndexOf methods give the same results.
			Debug.WriteLine( "Deleted row's index is " + row.Index );
			Debug.WriteLine( "Deleted row's index is " + row.ParentCollection.IndexOf( row ) );

			// You can also use the RemoveAt method to remove a row by specifying the 
			// index of the row instead of the row itself.
			ds.Rows.RemoveAt( 0, false );

			// Print out the row count. This should print 4 as the row count since we
			// added 5 using Add method in the for loop above and then added one
			// using the Insert method above and then removed two using Remove and
			// RemoveAt methods each.
			Debug.WriteLine( "Row count = " + ds.Rows.Count );

			// You can remove all rows from a row collection using Clear method. This
			// is more efficient than deleting individual rows using Remove or
			// RemoveAt methods.
			ds.Rows.Clear( );

			// You can use the SetCount method to add multiple rows at once. This can
			// be more efficient than adding individual rows using Add method when
			// adding a lot of rows.
			ds.Rows.SetCount( 5 );

			// Add another 5 rows by setting the count to 10. Previously we added 5
			// rows when we called SetCount( 5 ) above. Calling SetCount with 10 will
			// add another 5 rows so that the new count becomes 10.
			ds.Rows.SetCount( 10 );

			// Following line should print out 10.
			Debug.WriteLine( "Row count = " + ds.Rows.Count );

			ds.Rows.SetCount( 100000 );

			// Following line should print out 100000.
			Debug.WriteLine( "Row count = " + ds.Rows.Count );
		}
参照