Title: Treeview and Listview Controls
1Treeview and Listview Controls
- Tonga Institute of Higher Education
2Treeview Control
Parent of Students And Staff Nodes
- There are many controls you can use to create
professional software applications - Form
- Label
- LinkLabel
- TextBox
- Etc.
- A treeview control is useful as showing data in a
tree - Use tvw as a prefix treeviews
- Example tvwMinistryOfEducation
Nodes
Roots
Children of Tutors Node
3Treeview Properties
- BackColor
- Determines the background color of the form
- BorderStyle
- Determines the style of the border
- None
- FixedSingle
- Fixed3D
- CheckBoxes
- Determines whether a checkbox is displayed for
each node - Enabled
- Determines whether the user can use the control
- Font
- Determines the font of the text displayed
- FullRowSelect
- Determines whether a full row can be selected
- There is a bug where it wont work if ShowLines
and ShowPlusMinus are true - HideSelection
- Removes the highlight from the selected node when
control doesnt have focus - Location
- Scrollable
- Determines whether scroll bars should
automatically appear if the forms contents use
more space than the size of the form - ShowLines
- Determines whether lines are displayed
- ShowPlusMinus
- Determines whether plus/minus is displayed
- ShowRootLines
- Determines whether root lines are displayed
- Size
- Determines the current size of the form
- Sorted
- Determines whether the nodes are sorted
- TabIndex
- Determines the index of the Tab order that this
control will occupy - TabStop
- Determines whether the tab order will stop at
this control - Visible
- Determines the visibility of the control
- Anchor
4Adding Nodes through the Properties Window
- Click on Nodes in the properties window. A
button with 3 periods is displayed - Click on the button with 3 periods
- The Treenode Editor window is displayed
5Demonstration
- Changing Nodes through the Treeview Editor Window
6TreeNode Object
- Each node is a TreeNode object
- The TreeNode object has many properties and
methods - Checked
- Collapse
- Expand
- IsSelected
- IsVisible
- NextNode
- Parent
- PrevNode
- Remove
- Text
- And others
7TreeNodeCollection Object
- A collection of TreeNodes is a TreeNodeCollection
object - The TreeNodeCollection object has many properties
and methods - Clear
- Remove
- And Others
8Selecting a Node
- To select a node, we must find the location of
the node - tvwMain.SelectedNode tvwMain.Nodes(0).Nodes(1)
Nodes represents a TreeNodeCollection
Each level uses Nodes
Node Index starts from 0
The location of the node
Property allows selected node to be changed
9Controlling Treeviews with Code
TreeNodeCollection object controls the
collection of nodes
- Adding Nodes
- tvwMinistryOfEducation.Nodes.Add("New Root")
- Deleting Nodes
- tvwMinistryOfEducation.Nodes(0).Remove()
Text inside of new node
Control name
Method to add node
Finds a TreeNode object
Control name
Method to Delete node
10Demonstration
- Working with Treeviews through Code
11ListView Control
- Listviews allow users to display data in a table
- The properties are covered in IT142
12ListViewItem Object
- Each row is a ListViewItem object
- The ListViewItem object has many properties and
methods - Remove
- Selected
- And others
- To access a ListViewItem, find the location of
the ListViewItem
ListViewItem
13ListViewItemCollection Object
- A collection of ListViewItems is a
ListViewItemCollection object - The ListViewItemCollection object has many
properties and methods - Add
- Clear
- And Others
14Highlighting ListViewItems with Code
- lvwActivity2.Items(1).Selected True
Property to Select item
The location of the ListViewItem
15Adding ListViewItems with Code
We must add strings to subitems
16Demonstration
- Working with ListViews through Code