Gets or sets the specific list in a
DataSource for which the
System.Windows.Forms.DataGrid control displays a grid.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Visual Basic (Declaration)
Public Property DataMember As String
Dim instance As DataGrid
Dim value As String
value = instance.DataMember
instance.DataMember = value
public string DataMember { get; set; }
public:
property String^ DataMember {
String^ get ();
void set (String^ value);
}
/** @property */
public String get_DataMember ()
/** @property */
public void set_DataMember (String value)
public function get DataMember () : String
public function set DataMember (value : String)
Property Value
A list in a DataSource. The default is an empty string ("").
If a DataSource contains multiple sources of data, you should set the DataMember to one of the sources. For example, if the DataSource is a DataSet or DataViewManager that contains three tables named Customers, Orders, and OrderDetails, you must specify one of the tables to bind to. If the DataSet or DataViewManager contains only one DataTable, you should set the DataMember to the TableName of that DataTable.
If the DataSource is set to a DataSet that contains DataRelation objects, parent tables will appear with a plus sign (+) in each row header. Clicking the plus sign causes a node to appear that contains links to child tables. For example, if a DataSet contains two DataTable objects named Customers and Orders, setting the DataMember to the Customers table causes the System.Windows.Forms.DataGrid to display a parent table with a plus sign visible on each row header. If the DataMember is set to Orders, however, the row headers will be blank.
If the DataSource is a DataTable, DataView, collection, or array, setting the DataMember property throws an exception.
Note |
|---|
| At run time, you must use the SetDataBinding method to reset the DataSource property. However, the DataMember property alone can be reset at any time to a valid table name. |
The following code example sets the DataSource and DataMember properties of a System.Windows.Forms.DataGrid control.
Private Sub SetSourceAndMember()
Dim myDataSet As DataSet = New DataSet("myDataSet")
Dim customersTable As DataTable = new DataTable("Customers")
' Insert code to set source to populate DataSet.
' Set DataSource and DataMember with SetDataBinding method.
Dim member As String
' The name of a DataTable is Customers.
member = "Customers"
DataGrid1.SetDataBinding(myDataSet, member)
End Sub
protected object source;
private void SetSourceAndMember(){
DataSet myDataSet = new DataSet("myDataSet");
DataTable tableCustomers = new DataTable("Customers");
myDataSet.Tables.Add(tableCustomers);
// Insert code to populate the DataSet.
// Set DataSource and DataMember with SetDataBinding method.
string member;
// The name of a DataTable is Customers.
member = "Customers";
dataGrid1.SetDataBinding(myDataSet, member);
}
protected:
Object^ source;
private:
void SetSourceAndMember()
{
DataSet^ myDataSet = gcnew DataSet( "myDataSet" );
DataTable^ tableCustomers = gcnew DataTable( "Customers" );
myDataSet->Tables->Add( tableCustomers );
// Insert code to populate the DataSet.
// Set DataSource and DataMember with SetDataBinding method.
String^ member;
// The name of a DataTable is Customers.
member = "Customers";
dataGrid1->SetDataBinding( myDataSet, member );
}
protected Object source;
private void SetSourceAndMember()
{
DataSet myDataSet = new DataSet("myDataSet");
DataTable tableCustomers = new DataTable("Customers");
myDataSet.get_Tables().Add(tableCustomers);
// Insert code to populate the DataSet.
// Set DataSource and DataMember with SetDataBinding method.
String member;
// The name of a DataTable is Customers.
member = "Customers";
dataGrid1.SetDataBinding(myDataSet, member);
} //SetSourceAndMember
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
.NET Framework
Supported in: 2.0, 1.1, 1.0