⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attributelist.cs

📁 很好的带有编辑功能、量算功能。可在地图上进行距离、面积、角度测量
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data ;
using System.Data.SqlClient ; 

using ESRI.ArcGIS.Geodatabase ;
using ESRI.ArcGIS.Carto ;
using ESRI.ArcGIS.Geometry ;   
using ESRI.ArcGIS.Display ; 

namespace AoTest
{
	/// <summary>
	/// AttributeList 的摘要说明。
	/// </summary>
	public class AttributeList : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Splitter splitter1;
		private System.Windows.Forms.TreeView treeView1;
		private System.Windows.Forms.DataGrid dataGrid1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public AttributeList()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.panel1 = new System.Windows.Forms.Panel();
			this.splitter1 = new System.Windows.Forms.Splitter();
			this.treeView1 = new System.Windows.Forms.TreeView();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.panel1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.treeView1);
			this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
			this.panel1.Location = new System.Drawing.Point(0, 0);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(144, 273);
			this.panel1.TabIndex = 0;
			// 
			// splitter1
			// 
			this.splitter1.Location = new System.Drawing.Point(144, 0);
			this.splitter1.Name = "splitter1";
			this.splitter1.Size = new System.Drawing.Size(3, 273);
			this.splitter1.TabIndex = 1;
			this.splitter1.TabStop = false;
			// 
			// treeView1
			// 
			this.treeView1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.treeView1.ImageIndex = -1;
			this.treeView1.Location = new System.Drawing.Point(0, 0);
			this.treeView1.Name = "treeView1";
			this.treeView1.SelectedImageIndex = -1;
			this.treeView1.Size = new System.Drawing.Size(144, 273);
			this.treeView1.TabIndex = 0;
			this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
			// 
			// dataGrid1
			// 
			this.dataGrid1.DataMember = "";
			this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(147, 0);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.Size = new System.Drawing.Size(215, 273);
			this.dataGrid1.TabIndex = 2;
			// 
			// AttributeList
			// 
			this.AutoScale = false;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(362, 273);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.splitter1);
			this.Controls.Add(this.panel1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "AttributeList";
			this.ShowInTaskbar = false;
			this.Text = "AttributeList";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.AttributeList_Closing);
			this.panel1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		public void AddSelection( ESRI.ArcGIS.Geodatabase.ISelectionSet pSelection, string strLayer )
		{
			IQueryFilter pFilter = new QueryFilterClass();
			ICursor pCursor;

			pSelection.Search( pFilter , false, out pCursor);

			ESRI.ArcGIS.Geodatabase.IRow pRow;
			TreeNode pNode ;
			TreeNode pParent;
  
			pRow = pCursor.NextRow ();
			if ( pRow != null)
			{ 
				pParent = new TreeNode(strLayer);
				treeView1.Nodes.Add(pParent);  

				IRowBuffer pBuffer;
				do 
				{
					pBuffer = (IRowBuffer) pRow;
					pNode = new TreeNode(); 
					pNode.Text = pBuffer.get_Value(0).ToString();
					pParent.Nodes.Add(pNode);    

					pRow = pCursor.NextRow();
				}while(pRow != null);
//				pParent.Expand();
             }
		}

		public void ClearSelection()
		{
			treeView1.Nodes.Clear();
			dataGrid1.DataSource = null;
			dataGrid1.Refresh();		
		}

		private void AttributeList_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			ClearSelection();
		}

		private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
		{
			if (treeView1.SelectedNode == null  ) 
				return ;
			if (treeView1.SelectedNode.Parent == null) 
				return ;

			string strLayer ;
			string strKey ;

			strKey = treeView1.SelectedNode.Text ;
			strLayer = treeView1.SelectedNode.Parent.Text ;
  
			IFeatureLayer pLayer;
			Form1 pForm;

			pForm = (Form1) this.Owner ;
			int i;
			for(i=0 ; i< pForm.pMap.LayerCount ;i++)
			{
					if (pForm.pMap.get_Layer(i).Name == strLayer) 
						break;
			}
			pLayer = (IFeatureLayer) pForm.pMap.get_Layer(i);
			IFeatureCursor pCursor;
			IQueryFilter pFilter = new QueryFilterClass();
 
			pFilter.WhereClause = " FID = " + strKey ;
			
			pCursor = pLayer.Search(pFilter,false);

			IFeature pFeature ;
			IRowBuffer pRow;
			pFeature = pCursor.NextFeature();

			if (pFeature != null) 
			{
				pRow = (IRowBuffer) pFeature;
				FillDataGrid(pRow);

				IGeometry pGeometry = pFeature.Shape ;
				pForm.FlashShape(pGeometry);
			} 
 
		}


		private void FillDataGrid(IRowBuffer pBuffer)
		{
			DataTable pTable = new DataTable();

			pTable.Columns.Add("字段名");
			pTable.Columns.Add("字段取值");
			
			DataRow pRow;

			for (int i= 0;i<pBuffer.Fields.FieldCount; i++)
			{
				pRow=pTable.NewRow();  
				pRow["字段名"] = pBuffer.Fields.get_Field(i).Name ;
				pRow["字段取值"] = pBuffer.get_Value(i).ToString();
				pTable.Rows.Add(pRow);
			}
			pTable.Columns[0].ReadOnly = true;
			dataGrid1.DataSource =null;
			dataGrid1.DataSource = pTable;
            dataGrid1.Refresh();     
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -