Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 22 Tree View and List View

Similar presentations


Presentation on theme: "Chapter 22 Tree View and List View"— Presentation transcript:

1 Chapter 22 Tree View and List View
Pratyush Rai Yanmei Lan

2 Tree View Splitter List View

3 Splitters Used to divide the document into different regions.
Used in Microsoft Word to divide the document into different regions. Used in Windows Explorer. Implemented in the Splitter class, which is derived from Control. Associated with a target control through the mechanism of docking.

4 Docking Control class implements a property named Dock that can be assigned one of the following DockStyle enumeration. Member Value None Top 1 Bottom 2 Left 3 Right 4 Fill 5 If control is an instance of any class descended from Control control.Dock = DockStyle.Left;

5 .NET DESIGNER Toolbox Form Solution Explorer Properties Window

6 Docking contd.. What happens when two or more controls are docked against the same side? Behavior determined by the z-order of the controls.

7 Z- order Characteristics of the control at the top of z-order
It is the first control to be assigned its parent property. It is referenced by an index of 0 in the controls property. It is visually on top of all other controls. It is the control closest to the center of the client area when multiple controls are docked against the same edge of the container. Characteristics of the control at the bottom of z-order It is the last control to be assigned its parent property. It is referenced by an index of (Controls.Count-1) in the control collection. It is visually underneath all other controls. If multiple controls are docked against the same edge of the container, it’s the control on the edge.

8 Docking Examples Panel panel1 = new Panel(); panel1.Parent = this;
panel1.Dock = DockStyle.Fill; panel2.Dock = DockStyle.Fill; panel1.Dock = DockStyle.Left; panel2.Dock = DockStyle.Left; panel1 will be visible on top of panel2. The left part of panel2 will be obscured by panel1. Both the panels are completely visible here. panel2 is closer to the left side. panel1 gets pushed towards the center. panel2 is closer to the left side.

9 Using splitters Splitter used with a single panel – example on page 1050. Splitter used with two panels – example on page 1052.

10 Designer Drag a panel from the Toolbox on to the form. Set its Dock property to Left using the Properties Window. Drag a splitter on the form. Set its Dock property to Left as well. Drag a second panel on the form. Set its Dock property to Fill.

11 Splitter Properties Type Property Accessibility int SplitPosition
get/set MinSize MinExtra Width BorderStyle Color BackColor Splitter Events Event Method Delegate Argument SplitterMoving OnSplitterMoving SplitterEventHandler SplitterEventArgs SplitterMoved OnSplitterMoved

12 Tree Views and Tree Nodes
TreeView control is most commonly used to display a list of disk drives and directories. They can be used to display any hierarchical information. Bulk of tree view implementation consists of TreeView, TreeNode and TreeNodeCollection classes.

13 TreeNode An object of type TreeNode is a single entry in the tree view. A TreeNode object is associated with a string and optional image. In Windows Explorer, the string is a drive or directory name, and the images resemble disk drives and folders.

14 Properties TreeNode Properties (selection)
Type Property Accessibility TreeNodeCollection Nodes get TreeNodeCollection Properties Type Property Accessibility TreeNode [] get/set int Count get bool IsReadOnly TreeNodeCollection Methods (selection) TreeNode Add(string strNode) int Add(TreeNode node) void AddRange(TreeNode[] anode)

15 TreeView TreeView is a collection of top-level (or root) TreeNode objects. TreeView derives from Control, while TreeNode derives from MarshalByRefObject TreeView Properties (selection) Type Property Accessibility TreeNodeCollection Nodes get

16 Example SimpleTreeView.cs on page 1062
Each of the Add methods in the code creates a TreeNode object. tree.Nodes[0].Nodes.Add(“Dog”) – the first part of the statement refers to the first TreeNode object, that is “Animal”. The second Nodes property is the collection of child TreeNode objects of “Animals”.

17 Images in Tree Views TreeView Properties (selection)
Type Property Accessibility bool ShowPlusMinus get/set ShowLines ShowRootLines TreeView Properties (selection) Type Property Accessibility ImageList get/set int ImageIndex SelectedImageIndex

18 TreeNode Constructors
TreeNode(string strNode) TreeNode(string strNode, TreeNode[] anodes) TreeNode(string strNode, int indexImage, int indexImageSelected) TreeNode(string strNode, int indexImage, int indexImageSelected, TreeNode[] anodes)

19 Tree View Events The TreeNode class doesn’t define any events on its own. However, TreeView implements 11 events in addition to the ones it inherits from Control. Here are the 6 crucial ones: Event Method Delegate Argument BeforeExpand OnBeforeExpand TreeViewCancelEventHandler TreeViewCancelEventArgs BeforeCollapse OnBeforeCollapse BeforeSelect OnBeforeSelect AfterExpand OnAfterExpand TreeViewEventHandler TreeViewEventArgs AfterCollapse OnAfterCollapse AfterSelect OnAfterSElect

20 Node Navigation TreeNode Properties (selection)
Type Property Accessibility TreeView get int Index string Text get/set object Tag The following properties are read-only Type Property Accessibility TreeNode Parent get FirstNode LastNode NextNode PrevNode

21 Node Navigation contd.. TreeNode Properties (selection) Type Property
Accessibility bool IsExpanded get IsSelected string FullPath

22 Directory Tree DirectoryTreeView.cs on Page 1070.
DirectoriesAndFiles.cs on Page 1074. In DirectoryTreeView.cs, RefreshTree method calls AddDirectory to display the plus sign that allows the user to expand the node.

23 List View ListView control displays textual information in rows and columns with column headings. First column of information contains the list view items, and the other columns contain sub items associated with each item.

24 ListView Properties ListView Properties (selection) View Enumeration
Type Property Accessibility View get/set ImageList SmallImageList LargerImageList ListView.ColumnHeaderCollection Columns get ListView.ListViewItemCollection Items View Enumeration Member Value LargeIcon Details 1 SmallIcon 2 List 3

25 Properties contd.. ListView.ColumnHeaderCollection Properties
Type Property Accessibility ColumnHeader [] get int Count bool IsReadOnly ListView.ColumnHeaderCollection Methods (selection) int Add(ColumnHeader colhead) ColumnHeader Add(string strText, int iWidth, HorizontalAlignment ha) void AddRange(ColumnHeader[] acolheads)

26 Properties (again) ListView.ListViewItemCollection Properties
Type Property Accessibility ListViewItem [] Get/set int Count get bool IsReadOnly ListView. ListViewItemCollection Methods (selection) ListViewItem Add(ListViewItem lvitem) ListViewItem Add(string strItem) ListViewItem Add(string strItem, int indexImage) void AddRange(ListViewItem[] alvitems)

27 List View Events ListView Properties (selection)
Type Property Accessibility ItemActivation Activation get/set ItemActivation Enumeration Member Value Standard OneClick 1 TwoClick 2

28 List View Events ListView Events (selection) Event Method Delegate
Argument SelectedIndexChanged OnSelectedIndexChanged EventHandler EventArgs ItemActivate OnItemActivate ColumnClick OnColumnClick ColumnClickEventHandler ColumnClickEventArgs

29 Example Windows Explorer type application – page 1097.


Download ppt "Chapter 22 Tree View and List View"

Similar presentations


Ads by Google