ErrorProvider.DataSource Propriété

Définition

Obtient ou définit la source de données que ErrorProvider surveille.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

Valeur de propriété

Source de données basée sur l'interface IList dont les erreurs sont à surveiller.A data source based on the IList interface to be monitored for errors. En règle générale, il s'agit d'un DataSet dont les erreurs sont à surveiller.Typically, this is a DataSet to be monitored for errors.

Attributs

Exemples

L’exemple de code suivant montre comment utiliser ErrorProvider avec un DataSource et DataMember pour indiquer une erreur de données à l’utilisateur.The following code example shows how to use the ErrorProvider with a DataSource and DataMember to indicate a data error to the user. Ce code suppose que vous avez créé et rempli un DataSet nommé dataSet1 qui contient DataTable un dataTable1nommé.This code assumes you have created and populated a DataSet named dataSet1 containing a DataTable named dataTable1. Quand vous liez le DataSet à un contrôle tel que le DataGridView contrôle, les erreurs spécifiées par le biais DataRow d’objets apparaissent en DataGridView tant que glyphes d’erreur dans le contrôle.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
 '...
' 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

Remarques

DataSource Est une source de données que vous pouvez attacher à un contrôle et dont vous souhaitez analyser les erreurs.The DataSource is a data source that you can attach to a control and that you want to monitor for errors. DataSourcepeut être défini sur n’importe quelle collection qui IListimplémente.DataSource can be set to any collection that implements IList.

Pour éviter les conflits au moment de l’exécution qui peuvent DataSource se DataMemberproduire lors de la BindToDataAndErrors modification de et, DataMember vous devez utiliser au lieu de définir DataSource et individuellement.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.

S’applique à

Voir aussi