DataRepeater.AddNew Method

Adds a new DataRepeaterItem to the DataRepeater control.

Namespace:  Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

Syntax

'Declaration
Public Sub AddNew
public void AddNew()
public:
void AddNew()
member AddNew : unit -> unit
public function AddNew()

Exceptions

Exception Condition
ReadOnlyException

The AllowUserToAddItems property is set to False.

Remarks

Use this method to display a new DataRepeaterItem at the bottom of the DataRepeater control. Data for the controls in the DataRepeaterItem will be blank unless a default value is supplied by the DataSourceChanged event or in the AddNew method.

When the AllowUserToAddItems property is set to True, users can also add a new DataRepeaterItem by clicking the BindingNavigatorAddNewItemToolStripButton on the BindingNavigator control, or by pressing CTRL+N when a DataRepeaterItem has focus.

Examples

The following example demonstrates how to set default text in the AddNew method. It assumes that you have a form that contains a Button named AddNewButton and a bound DataRepeater control named DataRepeater1 that contains a TextBox control named ProductNameTextBox.

Private Sub AddNewButton_Click() Handles AddNewButton.Click
    ' Add a new repeater item.
    DataRepeater1.AddNew()
    ' Set the default text.
    DataRepeater1.CurrentItem.Controls("ProductNameTextBox").Text = 
       "New Product" 
End Sub
private void addNewButton_Click(object sender, System.EventArgs e)
{
    // Add a new repeater item.
    dataRepeater1.AddNew();
    // Set the default text.
    dataRepeater1.CurrentItem.Controls["productNameTextBox"].Text = "New Product";
}

.NET Framework Security

See Also

Reference

DataRepeater Class

Microsoft.VisualBasic.PowerPacks Namespace

Other Resources

Introduction to the DataRepeater Control (Visual Studio)

How to: Disable Adding and Deleting DataRepeater Items