XmlForm.DataSources Property (Microsoft.Office.InfoPath)
Gets the DataSourceCollection object associated with the form.
Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)
Syntax
'Declaration
Public MustOverride ReadOnly Property DataSources As DataSourceCollection
'Usage
Dim instance As XmlForm
Dim value As DataSourceCollection
value = instance.DataSources
public abstract DataSourceCollection DataSources { get; }
Property Value
A DataSourceCollection that contains any DataSource objects associated with the form.
Remarks
The DataSourceCollection object contains a collection of DataSource objects that represent all external (secondary) data sources associated with the form template. The DataSourceCollection object also contains a DataSource object that represents the main data source of the form. This means that developers will have two ways to return the DataSource object that represents the main data source: by using DataSourceCollection[""]
or by using the MainDataSource property.
Note
The DataSources property provides similar functionality to the DataObjects property of the XDocument object in the COM/Scripting object model, and to the DataObjects property of the _XDocument2 interface of the InfoPath 2003-compatible managed code object model.
This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.
This type or member can be accessed from code running in forms opened in Microsoft Office InfoPath 2007 or in a Web browser.
Example
In the following example, the DataSources property of the XmlForm class is used to set a reference to the "CityList" secondary data source.
DataSource myDataSource = this.DataSources["CityList"];
Dim myDataSource As DataSource = Me.DataSources("CityList")
In the following example, which implements an event handler for a Button control on a form, the DataSources property of the XmlForm object is used to set a reference to the DataSourceCollection of the form. The code loops through the collection and displays the positional index and name of each DataSource object that it contains.
public void CTRL1_Clicked(object sender, ClickedEventArgs e)
{
// Set a reference to the DataSources collection.
DataSourceCollection myDataSources = this.DataSources;
// Loop through the collection and display the name
// of each DataSource object that it contains.
for (int i = 0; i < myDataSources.Count; i++)
{
MessageBox.Show("Data source " + i + ": " +
myDataSources[i].Name);
}
}
Public Sub CTRL1_Clicked(ByVal sender As Object, _
ByVal e As ClickedEventArgs)
' Set a reference to the DataSources collection.
Dim myDataSources As DataSourceCollection = Me.DataSources
' Loop through the collection and display the name
' of each DataSource object that it contains.
Dim i As Integer
For i = 0 To myDataSources.Count - 1
MessageBox.Show("Data source " & i & ": " _
& myDataSources(i).Name)
Next
End Sub
See Also
Reference
XmlForm Class
XmlForm Members
Microsoft.Office.InfoPath Namespace