Parameter.OnParameterChanged Metodo

Definizione

Chiama il OnParametersChanged(EventArgs) metodo dell'insieme ParameterCollection che contiene l'oggetto Parameter .

protected:
 void OnParameterChanged();
protected void OnParameterChanged();
member this.OnParameterChanged : unit -> unit
Protected Sub OnParameterChanged ()

Esempio

Nell'esempio di codice seguente viene illustrato come chiamare il OnParameterChanged metodo per generare l'evento ParametersChanged quando lo stato di un parametro viene modificato. Questo esempio di codice fa parte di un esempio più ampio fornito per la panoramica della Parameter classe.

// The Value property is a type safe convenience property
// used when the StaticParameter represents string data.
// It gets the string value of the DataValue property, and
// sets the DataValue property directly.
public string Value {
  get {
    object o = DataValue;
    if (o == null || !(o is string))
      return String.Empty;
    return (string)o;
  }
  set {
    DataValue = value;
    OnParameterChanged();
  }
}
' The Value property is a type safe convenience property
' used when the StaticParameter represents string data.
' It gets the string value of the DataValue property, and
' sets the DataValue property directly.
Public Property Value() As String
   Get
      Dim o As Object = DataValue
      If o Is Nothing OrElse Not TypeOf o Is String Then
         Return String.Empty
      End If
      Return CStr(o)
   End Get
   Set
      DataValue = value
      OnParameterChanged()
   End Set
End Property

Commenti

Se l'oggetto Parameter non è contenuto da una ParameterCollection raccolta, la chiamata al OnParameterChanged metodo non ha alcun effetto. Se l'oggetto Parameter è contenuto da una ParameterCollection raccolta, OnParameterChanged genera l'evento ParameterCollection.ParametersChanged dell'insieme.

Se la ParameterCollection raccolta è contenuta da un controllo origine dati, l'evento ParameterCollection.ParametersChanged genera l'evento del DataSourceChanged controllo origine dati, causando la riassociazione di tutti i controlli associati a dati.

La generazione di un evento richiama il gestore eventi tramite un delegato. Per altre informazioni, vedere Gestione e generazione di eventi.

Il OnParameterChanged metodo consente anche alle classi derivate di gestire l'evento senza associare un delegato. Questa è la tecnica preferita per gestire l'evento in una classe derivata.

Note per gli eredi

Quando si esegue l'override OnParameterChanged() in una classe derivata, assicurarsi di chiamare il metodo della OnParameterChanged() classe di base in modo che i delegati registrati ricevano l'evento.

Si applica a

Vedi anche