close
文章出處

public partial class FrmAttributeTable : Form
    {
        private AxMapControl m_MapCtl;
        public FrmAttributeTable(AxMapControl pMapCtl)
        {
            InitializeComponent();
            m_MapCtl = pMapCtl;
        }

        private void FrmAttributeTable_Load_1(object sender, EventArgs e)
        {
            ILayer pLayer = m_MapCtl.get_Layer(0);
            IFeatureLayer pFLayer = pLayer as IFeatureLayer;
            IFeatureClass pFC = pFLayer.FeatureClass;

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

            DataTable pTable = new DataTable();

            for (int i = 0; i < pFC.Fields.FieldCount-2; i++)
            {
                string fieldName = pFC.Fields.get_Field(i+2).Name;

                DataColumn colName = new DataColumn(fieldName);
                colName.DataType = System.Type.GetType("System.String");
                //colName.Caption為顯示各用戶看的名稱。columnName改變的同時,caption也會變。
                pTable.Columns.Add(colName);
            }

            for (int j = 0; pFeature != null; j++)
            {
                DataRow pRow = pTable.NewRow();
                pTable.Rows.Add(pRow);
                for (int i = 0; i < pTable.Columns.Count; i++)
                {
                    string fieldValue = pFeature.get_Value(i + 2).ToString();//依次拿到各字段的值
                    
                    pTable.Rows[j][i] = fieldValue;
                }
                pFeature =  pFCursor.NextFeature();
            }
            

            dataGridView1.DataSource = pTable;

            //DataColumn colName = new DataColumn("ID");
            //colName.DataType = System.Type.GetType("System.String");
            //pTable.Columns.Add(colName);

            //DataColumn pBSM = new DataColumn("BSM");
            //pBSM.DataType = System.Type.GetType("System.String");
            //pTable.Columns.Add(pBSM);

            //DataColumn colArea = new DataColumn("TBMJ");
            //colArea.DataType = System.Type.GetType("System.String");
            //pTable.Columns.Add(colArea);

            //DataColumn colParameter = new DataColumn("TBZC");
            //colArea.DataType = System.Type.GetType("System.String");
            //pTable.Columns.Add(colParameter);
          
            
            
              


            //int indexOfID = pFC.FindField("ID");
            //int indexOfBSM = pFC.FindField("BSM");
            //int indexOfTBMJ = pFC.FindField("TBMJ");
            //int indexOfTBZC = pFC.FindField("TBZC");


            //while (pFeature != null)
            //{
            //    string id = pFeature.get_Value(indexOfID).ToString();
            //    string bsm = pFeature.get_Value(indexOfBSM).ToString();
            //    string TBMJ = pFeature.get_Value(indexOfTBMJ).ToString();
            //    string TBZC = pFeature.get_Value(indexOfTBZC).ToString();
            //    DataRow pRow = pTable.NewRow();
            //    pRow[0] = id;
            //    pRow[1] = bsm;
            //    pRow[2] = TBMJ;
            //    pRow[3] = TBZC;
            //    pTable.Rows.Add(pRow);
            //    pFeature = pFCursor.NextFeature();
            //}
            
        }
    }

 


不含病毒。www.avast.com
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 AutoPoster 的頭像
    AutoPoster

    互聯網 - 大數據

    AutoPoster 發表在 痞客邦 留言(0) 人氣()