BindingSource.ResetItem(Int32) Metoda

Definicja

Powoduje, że BindingSource kontrolka powiązana z elementem jest ponownie odczytywana w określonym indeksie i odświeża wyświetlaną wartość.

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

Parametry

itemIndex
Int32

Indeks zerowy elementu, który uległ zmianie.

Przykłady

Poniższy przykład kodu używa BindingSource składnika do powiązania listy z kontrolką DataGridView . Lista nie zgłasza powiadomień o zmianie, więc ResetItem metoda w obiekcie BindingSource jest używana do zgłaszania ListChanged zdarzenia. Ten przykład kodu jest częścią większego przykładu przedstawionego w temacie Instrukcje: zgłaszanie powiadomień o zmianie przy użyciu metody 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

Uwagi

Metoda ResetItem powiadamia wszystkie kontrolki powiązane z elementem w określonym Position celu, aby odświeżyć ich wartości. Metoda wykonuje to przez wywołanie ListChanged zdarzenia z ustawioną wartością ListChangedEventArgs.ListChangedTypeListChangedType.ItemChanged.

ResetItem jest automatycznie wywoływany za każdym razem, gdy zmiany zostaną wprowadzone do wartości pojedynczego elementu. Jednak programista może również jawnie wywołać tę metodę.

Dotyczy

Zobacz też