ListObject.DataSource Property (2007 System)
Gets or sets the source that contains a list of values that are used to populate the items within the control.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)
'Declaration
Public Property DataSource As Object
'Usage
Dim instance As ListObject
Dim value As Object
value = instance.DataSource
instance.DataSource = value
public Object DataSource { get; set; }
public:
property Object^ DataSource {
Object^ get ();
void set (Object^ value);
}
public function get DataSource () : Object
public function set DataSource (value : Object)
Type: System.Object
The source that contains a list of values that are used to populate the items within the control. The default value is nulla null reference (Nothing in Visual Basic).
At run time, use the SetDataBinding method to set the DataSource and DataMember properties.
The following data sources are valid:
A DataTable.
A DataView.
A DataSet.
Any component that implements the IListSource interface.
Any component that implements the IList interface.
See the Binding class overview for more information on data sources.
If the DataSource reference contains more than one table or property, you must set the DataMember property to a string that specifies the table to bind to. For example, if the DataSource is a DataSet or DataViewManager that contains three tables named Customers, Orders, and OrderDetails, you must specify the table to bind to.
Setting the DataSource to an object that does not implement the IList interface or an IListSource will cause an exception to be thrown.
The following code example creates a DataSet with two DataTable objects and populates one of the tables with data. The code then sets the DataSource and DataMember properties of the ListObject to bind to the table that contains data.
This example is for a document-level customization.
Private Sub ListObject_DataSourceAndMember()
' Create a DataSet and two DataTables.
Dim ordersDataSet As New DataSet("ordersDataSet")
Dim tableCustomers As New DataTable("Customers")
Dim tableProducts As New DataTable("Products")
ordersDataSet.Tables.Add(tableCustomers)
ordersDataSet.Tables.Add(tableProducts)
' Add a data to the Customers DataTable.
tableCustomers.Columns.Add(New DataColumn("LastName"))
tableCustomers.Columns.Add(New DataColumn("FirstName"))
Dim dr As DataRow = tableCustomers.NewRow()
dr("LastName") = "Chan"
dr("FirstName") = "Gareth"
tableCustomers.Rows.Add(dr)
' Create a list object.
Dim List1 As Microsoft.Office.Tools.Excel.ListObject = _
Me.Controls.AddListObject(Me.Range( _
"A1"), "Customers")
' Bind the list object to the Customers table.
List1.AutoSetDataBoundColumnHeaders = True
List1.DataSource = ordersDataSet
List1.DataMember = "Customers"
End Sub
private void ListObject_DataSourceAndMember()
{
// Create a DataSet and two DataTables.
DataSet ordersDataSet = new DataSet("ordersDataSet");
DataTable tableCustomers = new DataTable("Customers");
DataTable tableProducts = new DataTable("Products");
ordersDataSet.Tables.Add(tableCustomers);
ordersDataSet.Tables.Add(tableProducts);
// Add a data to the Customers DataTable.
tableCustomers.Columns.Add(new DataColumn("LastName"));
tableCustomers.Columns.Add(new DataColumn("FirstName"));
DataRow dr = tableCustomers.NewRow();
dr["LastName"] = "Chan";
dr["FirstName"] = "Gareth";
tableCustomers.Rows.Add(dr);
// Create a list object.
Microsoft.Office.Tools.Excel.ListObject list1 =
this.Controls.AddListObject(
this.Range["A1", missing], "Customers");
// Bind the list object to the Customers table.
list1.AutoSetDataBoundColumnHeaders = true;
list1.DataSource = ordersDataSet;
list1.DataMember = "Customers";
}
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.