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)

public void AddNew()

Exception Condition

The AllowUserToAddItems property is set to False.

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 BindingNavigatorAddNewItem ToolStripButton on the BindingNavigator control, or by pressing CTRL+N when a DataRepeaterItem has focus.

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 void addNewButton_Click(object sender, System.EventArgs e)
    // Add a new repeater item.
    // Set the default text.
    dataRepeater1.CurrentItem.Controls["productNameTextBox"].Text = "New Product";
Return to top