Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ErrorProvider.DataSource Property

Gets or sets the data set the ErrorProvider monitors.

[Visual Basic]
Public Property DataSource As Object
[C#]
public object DataSource {get; set;}
[C++]
public: __property Object* get_DataSource();
public: __property void set_DataSource(Object*);
[JScript]
public function get DataSource() : Object;
public function set DataSource(Object);

Property Value

A data set based on the IList interface to be monitored for errors. Typically, this is a DataSet to be monitored for errors.

Remarks

The DataSource is a DataSet containing tables with the fields that you can attach to a control and that you want to monitor for errors. DataSource can be set to any collection that implements IList.

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.

Example

[Visual Basic, C#, C++] The following example shows how to use the ErrorProvider with a DataSource and DataMember to indicate a data error to the user.

[Visual Basic] 
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. 

Protected Sub buttonSave_Click(sender As Object, e As System.EventArgs)
    ' Checks for a bad post code.
    Dim CustomersTable As DataTable
    CustomersTable = customersDataSet1.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

[C#] 
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. 
 }
 
 protected void buttonSave_Click(object sender, System.EventArgs e)
 {
     // Checks for a bad post code.
     DataTable CustomersTable;
     CustomersTable = customersDataSet1.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");
         } 
     } 
 }


[C++] 
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. 
 }
 
protected:
 void buttonSave_Click(Object* /*sender*/, System::EventArgs* /*e*/)
 {
     // Checks for a bad post code.
     DataTable* CustomersTable;
     CustomersTable = customersDataSet1->Tables->Item[S"Customers"];
     System::Collections::IEnumerator* myEnum = (CustomersTable->Rows)->GetEnumerator();
     while (myEnum->MoveNext())
     {
         DataRow* row = __try_cast<DataRow*>(myEnum->Current);
         if (Convert::ToBoolean(row->Item[S"PostalCodeIsNull"])) 
         {
             row->RowError=S"The Customer details contain errors";
             row->SetColumnError(S"PostalCode", S"Postal Code required");
         } 
     } 
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ErrorProvider Class | ErrorProvider Members | System.Windows.Forms Namespace | DataMember | IList

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft