• 字段排序


    我们知道表里面的记录是按照时间的顺序创建的,如果要对某一字段排序,ArcGIS的字段上点右键,但是当我们重新打开后,发现没有变化。写了断小代码可以对表的字段排序,没有对要素类排序,可以参考和修改代码

    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.Carto;
    using ESRI.ArcGIS.Geodatabase;
    using ESRI.ArcGIS.esriSystem;
    namespace TableSort
    {
        public partial class Sort : Form
        {
            private ITable pTable;
            IMap pMap;
            public Sort(IMap _pMap)
            {
                InitializeComponent();
                this.pMap = _pMap;
            }
            private void Sort_Load(object sender, EventArgs e)
            {
                IDataset pDataset = null;
                ITable plTable=null ;
                ITableCollection pTableCollection = pMap as ITableCollection;
                for (int i = 0; i < pTableCollection.TableCount; i++)
                {
                    plTable = pTableCollection.get_Table(i);
                    pDataset = plTable as IDataset;
                    comboBox1.Items.Add(pDataset.Name);
                   
                }

               comboBox1.Text = comboBox1.Items[0].ToString();
           
               FieldName(comboBox2, FindTable (pMap as ITableCollection  ,comboBox1.Text ));
               comboBox3.Items.Add("升序");
               comboBox3.Items.Add("降序");
               comboBox3.Text = comboBox3.Items[0].ToString();
            }
            private void FieldName(ComboBox _pComBox, ITable _pTable)
            {
                IFields pTableFields = _pTable.Fields;
                for (int i = 0; i < pTableFields.FieldCount; i++)
                {
                    if ( pTableFields.get_Field(i).Type != esriFieldType.esriFieldTypeOID)
                    {
                        _pComBox.Items.Add(pTableFields.get_Field(i).Name);
                    }
                }
               _pComBox.Text = _pComBox.Items[0].ToString();
            }
            private ITable FindTable(ITableCollection _pTabbleCollection, string _Name)
            {
                ITable plTable = null; ;
                IDataset plDataset;
                for (int i = 0; i < _pTabbleCollection .TableCount ;i++)
                {
                  
                    plDataset = _pTabbleCollection.get_Table(i) as IDataset;
                    if (plDataset.Name == _Name.Trim ())
                    {
                        plTable = _pTabbleCollection.get_Table(i);
                        break;
                    }
                }
                return plTable;
            }
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                FieldName(comboBox2, FindTable(pMap as ITableCollection, comboBox1.Text));
            }
            private void bOK_Click(object sender, EventArgs e)
            {
                pTable = FindTable(pMap as ITableCollection, comboBox1.Text);
                ITableSort plTalbeSort = new TableSortClass();
                plTalbeSort.Table = pTable;
                plTalbeSort.Fields = comboBox2.Text.Trim();
                if (comboBox3.Text.Trim () == "降序")
                {
                    plTalbeSort.set_Ascending(comboBox2.Text, false );
                }
                else
                {
                    plTalbeSort.set_Ascending(comboBox2.Text, true);
                }
                plTalbeSort.Sort(null);           
               
                ICursor plSortCursor = plTalbeSort.Rows;
                IRow pSortRow = plSortCursor .NextRow ();
                IDataset plSortDataset = pTable as IDataset;
                IFeatureWorkspace plFWS = plSortDataset.Workspace as IFeatureWorkspace;
               ITable plStable= plFWS.CreateTable("NewSort", pTable.Fields, null, null, null);

               while (pSortRow != null)
               {
                   IRow pRow = plStable.CreateRow();
                   for (int i=0;i <pRow .Fields .FieldCount;i++ )
                   {
                       if (pRow .Fields .get_Field (i).Type !=esriFieldType .esriFieldTypeOID)
                       {
                          pRow.set_Value (i,pSortRow .get_Value (i));
                       }
                   }
                   pRow.Store();
                   pSortRow = plSortCursor.NextRow();
               }
               ITableCollection pTC = pMap as ITableCollection;
               pTC.AddTable(plStable);
             
            }
           
        }

    }

  • 相关阅读:
    [C#]MagicLibrary.dll控件的使用(一)(下拉菜单)
    [SQL server]查询用户表及表结构
    [ASP.net]ASP.net的RUL重写
    [C#]简单XP菜单的实现(一)
    [Javascript]IFRAME运用(1)
    [ASP.net]未解的疑惑!
    [乱七八糟]Google搜索使用详细
    [Javascript]IFRAME运用(2)
    [随文杂记]残局
    [CSS]RevealTrans 滤镜
  • 原文地址:https://www.cnblogs.com/zuiyirenjian/p/1825318.html
Copyright © 2020-2023  润新知