『公告』 预祝您龙年大吉,万事如意, 过节期间, 大家如需数据服务,请拨打400 或直接添加客服微信,再祝大家龙年,心想事成。
关注我们 新浪 腾讯

ArcGIS Engine 10 开发手册(3-7)TOCContro控件

ArcGIS Engine 10 开发手册(3-7)TOCContro控件
TOCControl 控件使用的是用伙伴控件中的数据地图。

    TOCControl 控件使用的是用伙伴控件中的数据地图,它控制图层是否在伙伴控件空显示以及和伙伴控 件在符号上保持一致,TOCControl 为用户提供了一个交互式的环境,如果 TOCControl 控件的伙伴控件是 MapControl 控件,当我们将 TOCControl 控件中图层删掉是,MapControl 控件中相应的图层也会被删掉。

 

    显示属性表的信息

    我们知道ArcMap中的Table of Contents 有很多功能,如下图

 

 

 

     而 ArcGIS Engine 提供的 TOCControl 控件几乎没有提供,那么这些都是需要自己开发的,在这里我做一个 显示属性表的功能。

 

     功能分析

     要显示某一个图层的属性表,首先要将这个图层选中,然后在另外一个 Form 中将选中的这个图层 的属性信息进行显示。

 

     添加一个上下文菜单,添加一个新的 Form 窗体,在这个新的窗体上添加 GridView 控件,并在 TOCControl 控件的 OnMouseDown 事件下添加如下代码(pGlobalFeatureLayer 是我定义的一个全局变量):

 

private void axTOCControl1_OnMouseDown (object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent e) {

  if (axMapControl1.LayerCount > 0) {

    esriTOCControlItem pItem = new esriTOCControlItem ();

    pGlobalFeatureLayer = new FeatureLayerClass ();

    IBasicMap pBasicMap = new MapClass ();

    object pOther = new object ();

    object pIndex = new object ();

    axTOCControl1.HitTest (e.x, e.y, ref pItem, ref pBasicMap, ref pGlobalFeatureLayer, ref pOther, ref pIndex);

  }

  if (e.button == 2)

  {

    context.Show (axTOCControl1, e.x, e.y);

  }

}

在上下文菜单的打开属性表的 Click 事件中添加如下代码:

 

private void ToolStripMenuItem_Click (object sender, EventArgs e)

{

  FormTable Ft = new FormTable (pGlobalFeatureLayer as IFeatureLayer);

  Ft.Show ();

}

在新的窗体中添加一个将属性表显示到 GridView 控件中的函数,如下:

 

public void Itable2Dtable ()

{

  IFields pFields;

  pFields = pFeatureLayer.FeatureClass.Fields;

  dtGridView.ColumnCount = pFields.FieldCount;

  for (int i = 0; i < pFields.FieldCount; i++)

  {

    string fldName = pFields.get_Field (i).Name;

    dtGridView.Columns[i].Name = fldName;

    dtGridView.Columns[i].ValueType = System.Type.GetType (ParseFieldType (pFields.get_Field (i).Type));

  }

 

  IFeatureCursor pFeatureCursor;

  pFeatureCursor = pFeatureLayer.FeatureClass.Search (null, false);

  IFeature pFeature;

 

  pFeature = pFeatureCursor.NextFeature ();

  while (pFeature != null)

  {

    string[] fldValue = new string[pFields.FieldCount];

    for (int i = 0; i < pFields.FieldCount; i++)

    {

      string fldName;

      fldName = pFields.get_Field (i).Name;

      if (fldName == pFeatureLayer.FeatureClass.ShapeFieldName)

      {

        fldValue[i] = Convert.ToString (pFeature.Shape.GeometryType);

      } else

        fldValue[i] = Convert.ToString (pFeature.get_Value (i));

    }

    dtGridView.Rows.Add (fldValue);

    pFeature = pFeatureCursor.NextFeature ();

  }

}

 

 

    运行结果

    运行后,效果如下:

 

 

      京ICP备08100627号-22 京公网安备 11010802030428号