First effect:
This is the result of a Treeview control.
The usage of the control is not much said. For details, refer:
Http://msdn.microsoft.com/zh-cn/library/vstudio/system.windows.forms.treeview (V = vs.100). aspx
There is no image by default. To add an image to each node, you must first set the image list and then reference it.
The procedure is as follows:
1. initialize the image list
The purpose of initializing the image list is to add the image to the imagelist attribute list of the control for each tree node to call.
The Code is as follows:
private void InitImageList() { treeView.ImageList = new ImageList(); treeView.ImageList.Images.Add("GdbSource", Resource.GdbSource); treeView.ImageList.Images.Add("Database", Resource.GdbConnection16); treeView.ImageList.Images.Add("FeatureEmpty", Resource.GdbFeatureClassEmpty16); treeView.ImageList.Images.Add("FeatureLine", Resource.GdbFeatureClassLine16); treeView.ImageList.Images.Add("FeaturePoint", Resource.GdbFeatureClassPoint16); treeView.ImageList.Images.Add("FeaturePolygon", Resource.GdbFeatureClassPolygon16); treeView.ImageList.Images.Add("Dataset", Resource.GdbFeatureDataset16); }
Resource. *** is the referenced resource file. You can also reference the folder path file. The parameter after the add method is of the image type.
For reference to resource files, see: http://blog.csdn.net/zy332719794/article/details/8971154
2. Tree node reference image
Because the image list has been set in the first step, we only need to drop the image list directly when adding a tree node.
The Code is as follows:
private void NodeAddFeatureClass(TreeNode node, IFeatureClass featureClass) { switch (featureClass.ShapeType) { case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint: node.Nodes.Add("FeaturePoint", featureClass.AliasName, "FeaturePoint", "FeaturePoint"); break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline: node.Nodes.Add("FeatureLine", featureClass.AliasName, "FeatureLine", "FeatureLine"); break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon: node.Nodes.Add("FeaturePolygon", featureClass.AliasName, "FeaturePolygon", "FeaturePolygon"); break; default: node.Nodes.Add("FeatureEmpty", featureClass.AliasName, "FeatureEmpty", "FeatureEmpty"); break; } }
When adding a node, you can use the following methods:
Add (string)
--- Add a new tree node with the specified label text to the end of the current Tree node set.
Add (treenode) --- add the previously created Tree node to the end of the Tree node set.
Add (string,
String) --- specify the node key and display text.
Add (string,
String, int32) --- specify the node key, display text, image number
Add (string,
String, string) --- specify the node key, display text, image key
Add (string, String, int32, int32)
--- Specify the node key, display text, image number, and image number when selected
Add (string, String, string,
String) --- specifies the node key to display text, image number, and image key when selected
3. Note
(1) When adding images to imagelist, you can select the add method without adding keys. However, you must use add (string,
String, int32) or add (string,
String, int32, int32) method to add a tree node.
(2) If the image list is added but no specific image is called when the sub-node is added, the first (default) image of imagelist is added to each node by default.
(3) If the image number or key is not set when a tree node is added (the fourth parameter), the icon is changed to the first (default) image in imagelist.