Goal: Bind the menu to a flat database creating a hierarchical menu.
A secondary goal is to work exclusively within the design surface of Visual Studio.
To achieve the goals, this tutorial will walk you through the following steps:
- Telerik RadMenu can bind to flat data sources such as Access tables. Add an Access table to your project.
- Configure the data source.
- Bind the menu to the Access data source through the DataSourceID property of the menu.
- Create the menu hierarchy by binding the DataFieldID and DataFieldParentID properties of the menu.
- Use the DataBindings collection to populate the menu items with data.
This tutorial assumes that you:
- are using Visual Studio 2005
- have set up a project called DataBindings
- have added the RadControls folder (with its Menu subfolder)
- have removed from the Visual Studio Toolbox previous versions (if any) of Telerik RadMenu
- have added Telerik RadMenu to the Visual Studio Toolbox
Add an Access database to the project
The only requirement is for the Access data source to have columns that will populate the ID and ParentID properties of the menu. (The columns can have any names, not necessarily ID and ParentID) The parent ID for all root items should be null (nothing).
Below is a screenshot of the menu1.mdb Access table used in this tutorial. The most important columns are ID and ParentID - these will later be bound to the respective menu properties to provide the hierarchical structure of the menu:
Pic. 1

 |
It is not necessary for the names of the columns and the properties to be identical. |
- Copy the Access database to the root of your project.
- Drag an instance of Telerik RadMenu from the Toolbox to the design surface.
- Likewise, drag an instance of the AccessDataSource control. (Pic. 2)
Pic. 2
Configure the data source
Next, you need to configure the newly added data source as shown in Pic. 3 and Pic. 4:
Pic. 3
- Click the AccessDataSource smart tag.
- Click Configure Data Source.
- In the Configure Data Source dialog, click Browse. Select the newly added data source and then click OK.
The name and path appear under Microsoft Access data file.
- Click Next.
Pic. 4
- On the second screen of the wizard, select Specify columns from a table or view and from the drop-down, select Table 1.
- Select all columns (*).
- Go to the next screen.
- Optionally, you can click Test Query to check the database connection. When ready, click Finish.
Bind the menu to the data source
You can bind the menu in any of the following two ways:
- You can use the menu smart tag, as shown in Pic. 5:
Pic. 5
- Expand the Telerik RadMenu smart tag.
- Under Choose data source, select the ID of the Access data source.
- Alternatively, you can set the DataSourceID from the Properties window of the menu, as shown in Pic. 6.
Pic. 6
Milestone
If you build your project at this stage, the menu will appear similar to the one shown in Pic. 7 below:
Pic. 7
Create the menu hierarchy
Simply set the DataFieldID and DataFieldParentID properties as shown in Pic. 8:
Pic. 8
If you build the project now, the menu will look similar to the one shown in Pic. 9 below:
Pic. 9
Populate the menu items with data
You need to use the MenuItemBinding Collection Editor window. You can access the editor in either of the following ways:
-
Right-click the menu and select Edit Menuitem Databindings.
-
Click the Edit Menuitem Databindings shortcut at the bottom of the Properties window of the menu.
-
In the Properties window fo the menu, click the button in the row for the DataBindings property (as shown in Pic. 10 below).
Pic. 10
The MenuItemBinding Collection Editor window opens. Folow the instructions shown in Pic. 11:
Pic. 11
-
Add a data member to the collection.
-
Set the TextField and ToolTipField properties as illustrated.
-
Click OK.
If you build your project now, the menu will look similar to the one shown in Pic. 12:
Pic. 12
Thus our initial goal is achieved.
New goal: implement different binding logic for each level of hierarchy
Our menu has three levels of items. So far we have bound all levels using the same logic: the Text property of each item is populated from the Text column, whereas the ToolTip property takes its value from the Tooltip column. To do so, we used the TextField and ToolTipField properties of the DataBindings collection.
Our new goal is to:
-
populate the text of all second level items from the Text2 column of the Access table;
-
use the same tooltip for all second level items;
-
populate the text of all third level items from the Tooltip column.
To achieve our new goal, we need to add more data members to the DataBindings collection and set different depth for each new data member.
Add a data member for second-level items
As shown above, open the MenuItemBinding Collection Editor window and add a new data member.
Set the following properties:
- Depth = "1", to declare that this data member applies to second-level items;
- TextField = "Text2", to bind the second-level items to the Text2 column;
- ToolTip = "Custom tool tip here", to make each second-level item appear with the "Custom tool tip here" string as a tool tip.
 |
Text vs TextField, Value vs ValueField, etc. All properties ending with the suffix -Field can be databound to take their values from a corresponding field in the data source. Properties not ending with -Field are static: all MenuItem objects to which the MenuItemBinding object is applied share the same value.
For instance, if your database contains a column named Text and you set TextField="Text", the Text property of all menu items will take its value from the Text column in the database. Alternatively, if you set Text="Text", all your menu items will take the static string "Text" as the value of their Text property. |
If you build your project at this stage, you will notice how all second-level items have taken their values from the Text2 column in the database (Pic. 13).
Pic. 13
Add a data member for third-level items
Set the following properties:
- Depth = "2", to declare that this data member applies to third-level items;
- TextField = "Tooltip", to take the text of all third-level items from the Tooltip column;
Leave the ToolTipField and ToolTip properties blank. Third-level items will not have tool tips.
The final result should look similar to the one shown in Pic. 14 below:
Pic. 14

See Also