BindingSource.ResetItem(Int32) Método

Definición

Hace que un control enlazado al BindingSource vuelva a leer el elemento situado en el índice especificado y actualice su valor mostrado.

public:
 void ResetItem(int itemIndex);
public void ResetItem (int itemIndex);
member this.ResetItem : int -> unit
Public Sub ResetItem (itemIndex As Integer)

Parámetros

itemIndex
Int32

Índice de base cero del elemento que ha cambiado.

Ejemplos

En el ejemplo de código siguiente se usa un BindingSource componente para enlazar una lista a un DataGridView control . La lista no genera notificaciones de cambios, por lo que el ResetItem método de BindingSource se usa para generar el ListChanged evento. Este ejemplo de código forma parte de un ejemplo más grande proporcionado en Cómo: Generar notificaciones de cambio mediante el método BindingSource ResetItem.

// This event handler changes the value of the CompanyName
// property for the first item in the list.
void changeItemBtn_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   // Get a reference to the list from the BindingSource.
   List< DemoCustomer^ >^ customerList =
      static_cast<List< DemoCustomer^ >^>(
        this->customersBindingSource->DataSource);
   
   // Change the value of the CompanyName property for the
   // first item in the list.
   customerList->default[ 0 ]->CompanyName = L"Tailspin Toys";
   
   // Call ResetItem to alert the BindingSource that the
   // list has changed.
   this->customersBindingSource->ResetItem( 0 );
}
// This event handler changes the value of the CompanyName
// property for the first item in the list.
void changeItemBtn_Click(object sender, EventArgs e)
{
    // Get a reference to the list from the BindingSource.
    List<DemoCustomer> customerList = 
        this.customersBindingSource.DataSource as List<DemoCustomer>;

    // Change the value of the CompanyName property for the 
    // first item in the list.
    customerList[0].CompanyName = "Tailspin Toys";

    // Call ResetItem to alert the BindingSource that the 
    // list has changed.
    this.customersBindingSource.ResetItem(0);
}
' This event handler changes the value of the CompanyName
' property for the first item in the list.
Private Sub changeItemBtn_Click(ByVal sender As Object, ByVal e As EventArgs) _
   Handles changeItemBtn.Click

    ' Get a reference to the list from the BindingSource.
    Dim customerList As List(Of DemoCustomer) = _
    CType(Me.customersBindingSource.DataSource, List(Of DemoCustomer))

    ' Change the value of the CompanyName property for the 
    ' first item in the list.
    customerList(0).CompanyName = "Tailspin Toys"

    ' Call ResetItem to alert the BindingSource that the 
    ' list has changed.
    Me.customersBindingSource.ResetItem(0)

End Sub

Comentarios

El ResetItem método notifica a todos los controles enlazados al elemento en el especificado Position para actualizar sus valores. El método lo hace generando el ListChanged evento con ListChangedEventArgs.ListChangedType establecido en ListChangedType.ItemChanged.

ResetItem se llama automáticamente cada vez que se realizan cambios en el valor de un elemento individual. Sin embargo, el programador también puede llamar explícitamente a este método.

Se aplica a

Consulte también