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

public void AddNew()
public:
void AddNew()
member AddNew : unit -> unit
Public Sub 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 BindingNavigatorAddNewItem ToolStripButton 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 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";
}
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

See Also

DataRepeater Class
Microsoft.VisualBasic.PowerPacks Namespace
Introduction to the DataRepeater Control (Visual Studio)

242b7066-9b8a-495d-9936-4d1b4f6f6ac3

Return to top