ErrorProvider.DataSource 속성

정의

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

속성 값

IList 인터페이스를 기반으로 오류가 있는지 모니터링할 데이터 소스입니다.A data source based on the IList interface to be monitored for errors. 일반적으로, 이것은 오류가 있는지 모니터링할 DataSet입니다.Typically, this is a DataSet to be monitored for errors.

특성

예제

다음 코드 예제를 사용 하는 방법을 보여 줍니다 합니다 ErrorProvider 사용 하 여는 DataSourceDataMember 사용자에 게는 데이터 오류를 나타냅니다.The following code example shows how to use the ErrorProvider with a DataSource and DataMember to indicate a data error to the user. 이 코드에서는 만들고 채웁니다를 DataSet 라는 dataSet1 포함 하는 DataTable 라는 dataTable1합니다.This code assumes you have created and populated a DataSet named dataSet1 containing a DataTable named dataTable1. 바인딩하는 경우는 DataSet 와 같은 컨트롤에는 DataGridView 컨트롤을 통해 지정 된 오류 DataRow 개체에 오류 문자 모양으로 표시를 DataGridView 제어 합니다.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

설명

DataSource 는 컨트롤에 연결할 수 있는 데이터 원본 및 오류에 대 한 모니터링 하려는 합니다.The DataSource is a data source that you can attach to a control and that you want to monitor for errors. DataSource 구현 하는 컬렉션으로 설정할 수 있습니다 IList합니다.DataSource can be set to any collection that implements IList.

런타임에 변경 하는 경우 발생할 수 있는 충돌을 방지 하려면 DataSource 하 고 DataMember를 사용 해야 BindToDataAndErrors 설정 하는 대신 DataSourceDataMember 개별적으로 합니다.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.

적용 대상

추가 정보