Selecting Items in the TreeView
You determine whether to select all groups and child items, only groups, or only child items in the treeview by setting the AllowSelectItem property to True for the group or nested group you want to select.
To select groups in the treeview
To select groups in the treeview using the designer
1. Right-click on the C1WebTreeView control and select Edit from its context menu to open the C1WebCommandEditor.
2. Select C1WebTreeView1 in the tree view pane of the designer and set the AllowSelectItem and ShowCheckBoxes properties to True in the properties pane of the C1WebCommandEditor.
To select groups in the treeview programatically
1. Add a PlaceHolder control to the Web form.
2. Import the C1.Web.Command namespace to your Web page.
Imports C1.Web.Command
• C#
using C1.Web.Command;
3. Enter the following code in the Page_Load procedure to set the selection and check boxes for the groups in the treeview:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Create an instance of the class
Dim treeview As New C1WebTreeView()
'Add the C1WebTreeView control to the PlaceHolder control
PlaceHolder1.Controls.Add(treeview)
'create the C1WebTreeViewItem
Dim item As C1WebTreeViewItem
'Add items
treeview.Items.Add(New C1WebTreeViewItem("Item1"))
treeview.Items.Add(New C1WebTreeViewItem("Item2"))
'Enable selection for the group items in the treeview
treeview.AllowSelectItem = true
treeview.ShowCheckBoxes = true
'Have the nested items appear for the first group
item = CType(treeview.Items(0), C1WebTreeViewItem)
'Create a nested group
item.CreateChildGroup()
'Add items under the group
item.ChildGroup.Items.Add(New C1WebTreeViewItem("Item1.1"))
item.ChildGroup.Items.Add(New C1WebTreeViewItem("Item1.2"))
End Sub
• C#
protected void Page_Load(object sender, EventArgs e)
{
// Create an instance of the class
C1WebTreeView treeview = new C1WebTreeView();
treeview.Padding = Unit.Pixel(1);
treeview.GroupPadding = Unit.Pixel(1);
PlaceHolder1.Controls.Add(treeview);
C1WebTreeViewItem item;
//Add items
treeview.Items.Add(new C1WebTreeViewItem("Item1"));
treeview.Items.Add(new C1WebTreeViewItem("Item2"));
//Enable selection for the group items in the treeview
treeview.AllowSelectItem = true;
treeview.ShowCheckBoxes = true;
// Have the nested items appear for the first group
item = (C1WebTreeViewItem)treeview.Items[0];
// Create a nested group
item.CreateChildGroup();
// Add items under the group
item.ChildGroup.Items.Add(new C1WebTreeViewItem("Item1.1"));
item.ChildGroup.Items.Add(new C1WebTreeViewItem("Item1.2"));
}
This topic illustrates the following:
You can select the group items in the treeview at run time because the AllowSelectItem property was enabled for the C1WebTreeView1 control.
To select nested group items in the treeview
To select the nested group items in the treeview using the designer
1. Right-click on the C1WebTreeView control and select Edit from its context menu to open the C1WebCommandEditor.
2. Select C1WebTreeViewGroup in the tree view pane of the designer and set AllowSelectItem and ShowCheckBoxes to True in the properties pane of the C1WebCommandEditor.
To select the nested group items in the treeview programmatically
1. Add a PlaceHolder control to the Web form.
2. Import the C1.Web.Command namespace to your Web page.
Imports C1.Web.Command
• C#
using C1.Web.Command;
3. Enter the following code in the Page_Load procedure to set the selection and check boxes for the groups in the treeview:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Create an instance of the class
Dim treeview As New C1WebTreeView()
'Add the C1WebTreeView control to the PlaceHolder control
PlaceHolder1.Controls.Add(treeview)
'create the C1WebTreeViewItem
Dim item As C1WebTreeViewItem
'Add items
treeview.Items.Add(New C1WebTreeViewItem("Item1"))
treeview.Items.Add(New C1WebTreeViewItem("Item2"))
'Enable selection for the group items in the treeview
treeview.ShowCheckBoxes = true
'Have the nested items appear for the first group
item = CType(treeview.Items(0), C1WebTreeViewItem)
'Create a nested group
item.CreateChildGroup()
'Add items under the group
item.ChildGroup.Items.Add(New C1WebTreeViewItem("Item1.1"))
item.ChildGroup.Items.Add(New C1WebTreeViewItem("Item1.2"))
item.ChildGroup.AllowSelectItem = True
End Sub
• C#
protected void Page_Load(object sender, EventArgs e)
{
// Create an instance of the class
C1WebTreeView treeview = new C1WebTreeView();
treeview.Padding = Unit.Pixel(1);
treeview.GroupPadding = Unit.Pixel(1);
PlaceHolder1.Controls.Add(treeview);
C1WebTreeViewItem item;
//Add items
treeview.Items.Add(new C1WebTreeViewItem("Item1"));
treeview.Items.Add(new C1WebTreeViewItem("Item2"));
treeview.ShowCheckBoxes = true;
// Have the nested items appear for the first group
item = (C1WebTreeViewItem)treeview.Items[0];
// Create a nested group
item.CreateChildGroup();
// Add items under the group
item.ChildGroup.Items.Add(new C1WebTreeViewItem("Item1.1"));
item.ChildGroup.Items.Add(new C1WebTreeViewItem("Item1.2"));
//Enable the selection for the nested group items
item.ChildGroup.AllowSelectItem = true;
}
This topic illustrates the following:
You can select the nested group items in the treeview at run time because the AllowSelectItem property was enabled for the nested groups in the control.
|