加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

TOCControl控件右键显示图层属性

(2012-02-20 16:27:45)
标签:

杂谈

分类: GIS

(转载)

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();

             

            }

          

        }

 

运行后,效果如下:

 

 

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有