BindingSource.ResetItem(Int32) Metodo

Definizione

Fa sì che un controllo associato all'oggetto BindingSource esegua la rilettura dell'elemento posto in corrispondenza dell'indice specificato e aggiorni il relativo valore visualizzato.

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

Parametri

itemIndex
Int32

Indice in base zero dell'elemento modificato.

Esempio

Nell'esempio di codice seguente viene utilizzato un BindingSource componente per associare un elenco a un DataGridView controllo . L'elenco non genera notifiche di modifica, quindi il ResetItem metodo in BindingSource viene usato per generare l'evento ListChanged . Questo esempio di codice fa parte di un esempio più ampio fornito in Procedura: Generare notifiche di modifica usando il metodo ResetItem BindingSource.

// 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

Commenti

Il ResetItem metodo invia una notifica a tutti i controlli associati all'elemento in corrispondenza dell'oggetto specificato Position per aggiornare i relativi valori. Il metodo esegue questa operazione generando l'evento ListChanged con ListChangedEventArgs.ListChangedType impostato su ListChangedType.ItemChanged.

ResetItem viene chiamato automaticamente ogni volta che vengono apportate modifiche al valore di un singolo elemento. Tuttavia, il programmatore può anche chiamare questo metodo in modo esplicito.

Si applica a

Vedi anche