BindingSource.ResetItem(Int32) Metoda

Definice

Způsobí, že ovládací prvek svázaný s objektem BindingSource znovu načte položku v zadaném indexu a aktualizuje její zobrazenou hodnotu.

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

Parametry

itemIndex
Int32

Index položky, která se změnila od nuly.

Příklady

Následující příklad kódu používá komponentu BindingSource k vytvoření vazby seznamu s ovládacím prvkem DataGridView . Seznam nevyvolává oznámení o změnách, takže ResetItem k vyvolání ListChanged události se používá metoda na BindingSource . Tento příklad kódu je součástí většího příkladu uvedené v How to: Raise Change Notifications using the BindingSource ResetItem Method.

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

Poznámky

Metoda ResetItem upozorní všechny ovládací prvky vázané na položku v zadaném Position objektu, aby aktualizovaly jejich hodnoty. Metoda to dělá tak, že vyvolá ListChanged událost s nastavenou ListChangedEventArgs.ListChangedType na ListChangedType.ItemChanged.

ResetItem se automaticky volá při každé změně hodnoty jednotlivé položky. Programátor však může také volat tuto metodu explicitně.

Platí pro

Viz také