Export (0) Print
Expand All

ErrorProvider.DataMember Property

Gets or sets the data table to monitor.

[Visual Basic]
Public Property DataMember As String
[C#]
public string DataMember {get; set;}
[C++]
public: __property String* get_DataMember();
public: __property void set_DataMember(String*);
[JScript]
public function get DataMember() : String;
public function set DataMember(String);

Property Value

The string that represents a data table within the data set specified by the DataSource to be monitored. Typically, this will be a DataTable.

Remarks

The DataMember is a navigation string based on DataSource.

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

Show:
© 2014 Microsoft