1. 程式人生 > >【ArcEngine 10 二次開發】DataGridView顯示Layer中的屬性表

【ArcEngine 10 二次開發】DataGridView顯示Layer中的屬性表

顯示圖層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; } } }