码迷,mamicode.com
首页 > Windows程序 > 详细

【ArcEngine 10 二次开发】DataGridView显示Layer中的属性表

时间:2015-05-27 14:07:59      阅读:514      评论:0      收藏:0      [点我收藏+]

标签:datagridview   layer   arcengine   

显示图层Layer中的属性表

新建一个Form窗口

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;

namespace ArcTest
{
    public partial class AttributesTableForm2 : Form
    {

        private ILayer m_Layer;

        public AttributesTableForm2(ILayer pMapLayer)
        {
            InitializeComponent();
            m_Layer= pMapLayer;
        }

        private void AttributesTableForm2_Load(object sender, EventArgs e)
        {
            ILayer pLayer = m_Layer;

            IFeatureLayer pFLayer = pLayer as IFeatureLayer;

            IFeatureClass pFC = pFLayer.FeatureClass;

            IFeatureCursor pFCursor = pFC.Search(null, false);

            IFeature pFeature = pFCursor.NextFeature();

            DataTable pTable = new DataTable();

            //添加自定义字段
            DataColumn colName = new DataColumn("省 直辖市");

            colName.DataType = System.Type.GetType("System.String");

            pTable.Columns.Add(colName);

            //添加自定义字段
            DataColumn colArea = new DataColumn("面积");

            colArea.DataType = System.Type.GetType("System.Double");

            pTable.Columns.Add(colArea);

            int indexOfName = pFC.FindField("CHINESE");

            int indexOfArea = pFC.FindField("Area");

            while(pFeature != null)
            {
                string name = pFeature.get_Value(indexOfName).ToString();
                double area = (double)pFeature.get_Value(indexOfArea);

                DataRow pRow = pTable.NewRow();

                pRow[0] = name;

                pRow[1] = area;

                pTable.Rows.Add(pRow);

                pFeature = pFCursor.NextFeature();

            }

            dataGridView1.DataSource = pTable;
        }
    }
}

【ArcEngine 10 二次开发】DataGridView显示Layer中的属性表

标签:datagridview   layer   arcengine   

原文地址:http://blog.csdn.net/gdp12315_gu/article/details/46044427

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!