zoukankan      html  css  js  c++  java
  • arcEngine开发之查看属性表

    这篇文章给出实现属性表功能的具体步骤,之后再对这些步骤中的代码进行分析。

    环境准备

    • 拖动TOCControl、MapControl控件到Form窗体上,然后拖动ContextMenuStrip控件至TOCControl上。
      这里写图片描述

    TOCControl控件的OnMouseDown事件

    如果要使用属性表功能,首先应该保证鼠标点击在TOCControl上的图层,其次应该保证是使用鼠标右键点击的。实现这些判断的代码如下:

    这里的TOCControl.HitTest() 方法将鼠标点击位置的X,Y,元素类型,地图,图层等一系列值都付给参数。

    private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e)
    {
        if (e.button == 2)
        {
            IFeatureLayer pTocFeatureLayer = null;
            esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;
            IBasicMap pMap = null; object unk = null;
            object data = null; ILayer pLayer = null;
            axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLayer, ref unk, ref data);
            pTocFeatureLayer = pLayer as IFeatureLayer;
            if (pItem == esriTOCControlItem.esriTOCControlItemLayer && pTocFeatureLayer != null)
            {
               contextMenuStrip1.Show(Control.MousePosition);
            }
        }
    }
    

    查看图层属性表

    初始化属性表到 DataGridView 中,将这个过程封装到InitUi方法中

    在这个方法中,主要是设置 DataGridView 的数据源 ,其数据源属性 DataSource 应该为 DataTable 接口 ,该接口通过 DataTable.Columns.Add() 和 DataTable.Rows.Add() 来添加行与列。

    public void InitUI()
    {
    	IFeature pFeature = null;
    	DataTable pFeatDT = new DataTable();
    	DataRow pDataRow = null;
    	DataColumn pDataCol = null;
    	IField pField = null;
    	for(int i=0;i<_currentFeatureLayer.FeatureClass.Fields.FieldCount;i++)
    	{
    		pDataCol = new DataColumn();
    		pField = _currentFeatureLayer.FeatureClass.Fields.get_Field(i);
    		pDataCol.ColumnName = pField.AliasName; //获取字段名作为列标题
            pDataCol.DataType = Type.GetType("System.Object");//定义列字段类型
            pFeatDT.Columns.Add(pDataCol); //在数据表中添加字段信息
    	}
    	IFeatureCursor pFeatureCursor = _curFeatureLayer.Search(null, true);
        pFeature = pFeatureCursor.NextFeature();
        while (pFeature != null)
        {
            pDataRow = pFeatDT.NewRow();
            //获取字段属性
            for (int k = 0; k < pFeatDT.Columns.Count; k++)
            {
                pDataRow[k] = pFeature.get_Value(k);
            }
            
            pFeatDT.Rows.Add(pDataRow); //在数据表中添加字段属性信息
            pFeature = pFeatureCursor.NextFeature();
        }
           //释放指针
         System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
         //dataGridAttribute.BeginInit();
         dataGridAttribute.DataSource = pFeatDT;
    }
    
  • 相关阅读:
    虚拟机中按键切回windows系统界面快捷键
    余数
    质数(素数)判断代码实现
    =excel========》函数使用
    python 正则表达式规则
    linux常用命令详解
    c指针
    visual studio 2015 开发时常见问题的解决方案
    python装饰器
    构造方法
  • 原文地址:https://www.cnblogs.com/firepation/p/8510967.html
Copyright © 2011-2022 走看看