ErrorProvider.DataMember Proprietà

Definizione

Ottiene o imposta l'elenco all'interno di un'origine dati da controllare.

public:
 property System::String ^ DataMember { System::String ^ get(); void set(System::String ^ value); };
public string DataMember { get; set; }
public string? DataMember { get; set; }
member this.DataMember : string with get, set
Public Property DataMember As String

Valore della proprietà

Stringa che rappresenta un elenco all'interno dell'origine dati specificata dalla proprietà DataSource da controllare. In genere, si tratterà di un oggetto DataTable.

Esempio

Nell'esempio di codice seguente viene illustrato come usare l'oggetto ErrorProvider con un DataSource e DataMember per indicare un errore di dati all'utente.

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

Commenti

È DataMember una stringa di spostamento basata su DataSource.

Per evitare conflitti in fase di esecuzione che possono verificarsi quando si modifica DataSource e DataMember, è consigliabile usare BindToDataAndErrors anziché impostare DataSource e DataMember singolarmente.

Si applica a