ErrorProvider.DataMember 属性

定义

获取或设置数据源中要监视的列表。

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

属性值

表示 DataSource 指定的数据源内要被监视的列表的字符串。 通常情况下,这是一个 DataTable

示例

下面的代码示例演示如何将 ErrorProvider 与 一起使用 DataSource ,并 DataMember 向用户指示数据错误。

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

注解

DataMember是基于 的导航字符串DataSource

为了避免在运行时更改 DataSourceDataMember时可能发生的冲突,应使用 BindToDataAndErrors 而不是单独设置 DataSourceDataMember

适用于