ErrorProvider.DataSource ErrorProvider.DataSource ErrorProvider.DataSource ErrorProvider.DataSource Property

Definizione

Ottiene o imposta l'origine dati controllata dall'oggetto ErrorProvider.Gets or sets the data source that the ErrorProvider monitors.

public:
 property System::Object ^ DataSource { System::Object ^ get(); void set(System::Object ^ value); };
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public object DataSource { get; set; }
member this.DataSource : obj with get, set
Public Property DataSource As Object

Valore della proprietà

Origine dati basata sull'interfaccia IList in cui verificare la presenza di errori.A data source based on the IList interface to be monitored for errors. Generalmente, si tratta di un oggetto DataSet in cui verificare la presenza di errori.Typically, this is a DataSet to be monitored for errors.

Esempi

Esempio di codice seguente viene illustrato come utilizzare il ErrorProvider con un DataSource e DataMember per indicare un errore nei dati all'utente.The following code example shows how to use the ErrorProvider with a DataSource and DataMember to indicate a data error to the user. Questo codice presuppone di aver creato e popolato un DataSet denominate dataSet1 contenente un DataTable denominato dataTable1.This code assumes you have created and populated a DataSet named dataSet1 containing a DataTable named dataTable1. Quando si associa la DataSet a un controllo, ad esempio il DataGridView controllare, gli errori specificati tramite DataRow gli oggetti vengono visualizzati come icone di errore nel DataGridView controllo.When you bind the DataSet to a control such as the DataGridView control, errors specified through DataRow objects appear as error glyphs in the DataGridView control.

private:
   void InitializeComponent()
   {
      
      // Standard control setup.
      //....
      // You set the DataSource to a data set, and the DataMember to a table.
      errorProvider1->DataSource = dataSet1;
      errorProvider1->DataMember = dataTable1->TableName;
      errorProvider1->ContainerControl = this;
      errorProvider1->BlinkRate = 200;
      
      //...
      // Since the ErrorProvider control does not have a visible component,
      // it does not need to be added to the form. 
   }


private:
   void buttonSave_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      
      // Checks for a bad post code.
      DataTable^ CustomersTable;
      CustomersTable = dataSet1->Tables[ "Customers" ];
      System::Collections::IEnumerator^ myEnum = (CustomersTable->Rows)->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         DataRow^ row = safe_cast<DataRow^>(myEnum->Current);
         if ( Convert::ToBoolean( row[ "PostalCodeIsNull" ] ) )
         {
            row->RowError = "The Customer details contain errors";
            row->SetColumnError( "PostalCode", "Postal Code required" );
         }
      }
   }
private void InitializeComponent()
 {
     // Standard control setup.
     //....
     // You set the DataSource to a data set, and the DataMember to a table.
     errorProvider1.DataSource = dataSet1 ;
     errorProvider1.DataMember = dataTable1.TableName ;
     errorProvider1.ContainerControl = this ;
     errorProvider1.BlinkRate = 200 ;
     //...
     // Since the ErrorProvider control does not have a visible component,
     // it does not need to be added to the form. 
 }
 
 private void buttonSave_Click(object sender, System.EventArgs e)
 {
     // Checks for a bad post code.
     DataTable CustomersTable;
     CustomersTable = dataSet1.Tables["Customers"];
     foreach (DataRow row in (CustomersTable.Rows)) 
	 {
         if (Convert.ToBoolean(row["PostalCodeIsNull"])) 
         {
             row.RowError="The Customer details contain errors";
             row.SetColumnError("PostalCode", "Postal Code required");
         } 
     } 
 }

Private Sub InitializeComponent()
    ' Standard control setup.
    '....                  
    ' You set the DataSource to a data set, and the DataMember to a table.
    errorProvider1.DataSource = dataSet1
    errorProvider1.DataMember = dataTable1.TableName
    errorProvider1.ContainerControl = Me
    errorProvider1.BlinkRate = 200
End Sub 'InitializeComponent
 '...
' Since the ErrorProvider control does not have a visible component,
' it does not need to be added to the form. 

Private Sub buttonSave_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    ' Checks for a bad post code.
    Dim CustomersTable As DataTable
    CustomersTable = dataSet1.Tables("Customers")
    Dim row As DataRow
    For Each row In CustomersTable.Rows
        If Convert.ToBoolean(row("PostalCodeIsNull")) Then
            row.RowError = "The Customer details contain errors"
            row.SetColumnError("PostalCode", "Postal Code required")
        End If
    Next row
End Sub 'buttonSave_Click

Commenti

Il DataSource è un'origine dati che è possibile collegare a un controllo e che si desidera verificare la presenza di errori.The DataSource is a data source that you can attach to a control and that you want to monitor for errors. DataSource può essere impostato su qualsiasi raccolta che implementa IList.DataSource can be set to any collection that implements IList.

Per evitare i conflitti in fase di esecuzione che può verificarsi quando si modificano DataSource e DataMember, è consigliabile usare BindToDataAndErrors anziché impostare DataSource e DataMember singolarmente.To avoid conflicts at run time that can occur when changing DataSource and DataMember, you should use BindToDataAndErrors instead of setting DataSource and DataMember individually.

Si applica a

Vedi anche