Type | Description | |||
Variant | A VARIANT expression that could be a string, an object as explained bellow. |
For instance,
where ... indicates the full path to the sample file.
The control's DataSource property in BNF syntax is:
<DataSource> ::= <DataSourceView> [ ">>>" <DataSourceView> ] <DataSourceView> ::= <AltDataSourceView> [ "|||" <AltDataSourceView> ] <AltDataSourceView> ::= <DataField> [";" <DataField>] <DataField> ::= <DataFieldName> "=" <DataFieldValue> <DataFieldName> ::= ["Data "]"Source" | ["Data "]"Member" | ["Data "]"Key" | ["Data "]"Tag" | ["Data "]"Name" | <ExtraDataFieldName> <ExtraDataFieldName> ::= any extra field <DataFieldValue> ::= field's value
In other words, the DataSource property provides data source for each view separated by >>> sequence, and for each view different alternatives to create the view separated by ||| sequence. The DataSource can include sequences between <% and %> which are filled at runtime, based on the current selection in all views.
Let's examine the following DataSource sequence:
"Source=...\cities.mdb ; Member=Select * FROM Countries ; Key=CountryCode ; Tag=Country ; Name=CountryName >>> Member=Select * FROM States WHERE CountryCode IN (<%Parent.CountryCode%>) ; Key=StateCode ; Name=StateName ; Tag=State ||| Member=Select * FROM Cities WHERE CountryCode IN (<%Parent.CountryCode%>) ; Tag=City ; Name=Name >>> Member=Select * FROM Cities WHERE CountryCode IN (<%Parent.Parent.CountryCode%>) AND StateCode IN (<%Parent.StateCode%>) ; Tag=City ; Name=Name "
which can generate data source for up to 3 views red (country), green (state/city) and blue(city) as follows:
"Source=...\cities.mdb ; Member=Select * FROM Countries ; Key=CountryCode ; Tag=Country ; Name=CountryName >>> Member=Select * FROM States WHERE CountryCode IN (<%Parent.CountryCode%>) ; Key=StateCode ; Name=StateName ; Tag=State ||| Member=Select * FROM Cities WHERE CountryCode IN (<%Parent.CountryCode%>) ; Tag=City ; Name=Name >>> Member=Select * FROM Cities WHERE CountryCode IN (<%Parent.Parent.CountryCode%>) AND StateCode IN (<%Parent.StateCode%>) ; Tag=City ; Name=Name "
At runtime, these three views may shows as:
In the same time, each view's DataSource shows as:
For instance, Antartica has no states, the Member=Select * FROM States WHERE CountryCode IN (<%Parent.CountryCode%>) generates no results, and so the alternative data source is used Member=Select * FROM Cities WHERE CountryCode IN (<%Parent.CountryCode%>), so at runtime the views may shows as:
In the same time, each view's DataSource shows as:
Internally, the control's DataSource builds the view's DataSource with code as follows:
Private Sub CascadeTree1_CreateView(ByVal View As Object) With View Select Case View.Index Case 1: ' State or City .DataSource = CurrentDb.OpenRecordset("Select * FROM States WHERE CountryCode IN (" & .ParentView.ValueList("CountryCode") & " )") .Key = "StateCode" .Name = "StateName" .Tag = "State" If (.Items.ItemCount = 0) Then .DataSource = CurrentDb.OpenRecordset("Select * FROM Cities WHERE CountryCode IN (" & .ParentView.ValueList("CountryCode") & " )") .Key = "" .Tag = "City" .Name = "Name" End If Case 2: ' City .DataSource = CurrentDb.OpenRecordset("Select * FROM Cities WHERE CountryCode IN (" & .ParentView.ParentView.ValueList("CountryCode") & ") AND StateCode IN (" & .ParentView.ValueList("StateCode") & ")") .Key = "" .Tag = "City" .Name = "Name" End Select End With End Sub Private Sub Form_Load() With CascadeTree1 .BeginUpdate With .DefaultView .DataSource = CurrentDb.OpenRecordset("SELECT * FROM Countries") .Key = "CountryCode" .Tag = "Country" .Name = "CountryName" End With .EndUpdate End With End Sub
The DataSource property supports the following fields:
Each sequence between <% and %> characters indicates the value of the current selection into a specified View of the specified Column/Field, and must be of the following BNF syntax:
<value> ::= "<%" <view> "." <column> "%>" <view> ::= <parentview> [ "." <parentview> | <indexview> <parentview> := "Parent" <indexview> := 0 | 1 | 2 | ... <column> := <index> | <name> <index> := any index of any field into the Data Member <name> := any name of the field into the Data Member / any caption of the column into the viewFor instance:
- <%Parent.StateCode%>, indicates the value of the selection into the parent view of the column "StateCode".
- <%0.CountryCode%>, indicates the value of the selection into the view with the index 0 of the column "CountryCode".
- <%Parent.Parent.CountryCode%>, indicates the value of the selection into the parent of the parent view of the column "CountryCode".
- <%1.2%>, indicates the value of the selection into view with the index 1, on the column with the index 2
The View.ValueList property generates the values on the specified column ( Key column ) for all selected items, separated by , (comma) character. The ValueList property automatically includes ' character for strings and # for date fields. For instance, "'AZ','FL','CO','HI','IN'" or "1,2"
The Error event notifies your application once any internal error occurs. You can use the Description parameter of the Error event to find out more information about connection your data to the control.
Also the DataSource supports any of the following type of objects:
Safe-Array:
With CascadeTree1.DefaultView .LinesAtRoot = exLinesAtRoot .DataSource = Array("Item 1", Array("Sub-Item 1", "Sub-Item 2"), "Item 2") End With
/NET or /WPF Version (VB)
With Excascadetree1.DefaultView .LinesAtRoot = exLinesAtRoot .DataSource = New Object() {"Item 1", New Object() {"Sub-Item 1", "Sub-Item 2"}, "Item 2"} End With
/NET or /WPF Version (C#)
object[] items = {"Item 1", new object[] {"Sub-Item 1", "Sub-Item 2"}, "Item 2"}; excascadetree1.DataSource = items;
adds items from a safe-array. If it includes inside-safe arrays, it adds child items, and so on.
XML file name, a URL, an IStream, an IXMLDOMDocument
With CascadeTree1 .DataSource = "C:\Program Files\Exontrol\ExCascadeTree\Sample\testing.xml" End With
or:
With CascadeTree1.DefaultView .DataSource = "C:\Program Files\Exontrol\ExCascadeTree\Sample\testing.xml" End With
or:
With CascadeTree1.DefaultView Set xml = CreateObject("MSXML.DOMDocument") With xml .Load "C:\Program Files\Exontrol\ExCascadeTree\Sample\testing.xml" End With .DataSource = xml End With
ADO (Jet):
With CascadeTree1 Set ado = CreateObject("ADODB.Recordset") With ado .Open "Countries", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Exontrol\ExCascadeTree\Sample\Access\cities.mdb", 3, 3 End With .DataSource = ado End With
or:
With CascadeTree1 Set ado = CreateObject("ADODB.Recordset") With ado .Open "Countries", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Exontrol\ExCascadeTree\Sample\Access\cities.mdb", 3, 3 End With .DefaultView.DataSource = ado End With
ADO (OLEDB):
With CascadeTree1 Set ado = CreateObject("ADODB.Recordset") With ado .Open "Countries", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Program Files\Exontrol\ExCascadeTree\Sample\Access\cities.accdb", 3, 3 End With .DataSource = ado End With
or:
With CascadeTree1 Set ado = CreateObject("ADODB.Recordset") With ado .Open "Countries", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Program Files\Exontrol\ExCascadeTree\Sample\Access\cities.accdb", 3, 3 End With .DefaultView.DataSource = ado End With
DAO:
With CascadeTree1 .DataSource = CurrentDb.OpenRecordset("Countries") End With
or:
As Microsoft Access uses DAO, you need to use the View's DataSource property rather than control's DataSource property as in the following sample:With CascadeTree1.DefaultView .DataSource = CurrentDb.OpenRecordset("Countries") End With
Private Sub CascadeTree1_CreateView(ByVal View As Object) With View Select Case .Index Case 1: ' State or City .DataSource = CurrentDb.OpenRecordset("Select * FROM States WHERE CountryCode IN (" & .ParentView.ValueList("CountryCode") & " )") .Tag = "State" .Key = "StateCode" .Name = "StateName" If (.Items.ItemCount = 0) Then .DataSource = CurrentDb.OpenRecordset("Select * FROM Cities WHERE CountryCode IN (" & .ParentView.ValueList("CountryCode") & " )") .Tag = "City" .Key = "" .Name = "Name" .ColumnAutoResize = False End If Case 2: ' City .DataSource = CurrentDb.OpenRecordset("Select * FROM Cities WHERE CountryCode IN (" & .ParentView.ParentView.ValueList("CountryCode") & ") AND StateCode IN (" & .ParentView.ValueList("StateCode") & ")") .Tag = "City" .Key = "" .Name = "Name" End Select End With End Sub Private Sub Form_Load() With CascadeTree1.DefaultView .DataSource = CurrentDb.OpenRecordset("SELECT * FROM Countries") .Tag = "Country" .Key = "CountryCode" .Name = "CountryName" End With End Sub
The sample loads the Countries table into the default view ( view with the index 0 ). Once the user clicks / selects / activates an item, the control creates a new view ( with the index 1, 2 and so on ) and fires the CreateView event. During the CreateView event you can load data from different tables based on the parent's view selection. See the ParentView.ValueList