www.pudn.com > MyVR.rar > TableForm.cs, change:2008-06-05,size:4463b


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
 
using ESRI.ArcGIS.esriSystem; 
using ESRI.ArcGIS.SystemUI; 
using ESRI.ArcGIS.Geometry; 
using ESRI.ArcGIS.Display; 
using ESRI.ArcGIS.Geodatabase; 
using ESRI.ArcGIS.Carto; 
using ESRI.ArcGIS.Controls; 
using ESRI.ArcGIS.Analyst3D; 
namespace MyVR 
{ 
    public partial class TableForm : Form 
    { 
        //public IMapControl2 pMapControl; 
        //public IMap pMap; 
        //public int iLayerIndex; 
        //public string LayerName; 
        public ISceneControl pSceneControl; 
        public IScene pScene; 
        public int iLayerIndex; 
        public string LayerName; 
        public TableForm() 
        { 
            InitializeComponent(); 
        } 
        public TableForm(ISceneControl pfSceneControl,string LyrName) 
        { 
            InitializeComponent(); 
            pSceneControl = pfSceneControl; 
            pScene = pSceneControl.Scene; 
            LayerName = LyrName; 
  
        } 
 
        private void TableForm_Load(object sender, EventArgs e) 
        { 
            GetAllValues(); 
        } 
        public void GetAllValues() 
        { 
 
            IFeatureLayer pFeatureLayer; 
 
            for (int i = 0; i < pScene.LayerCount; i++) 
            { 
                if (LayerName == pScene.get_Layer(i).Name) 
                { 
                    iLayerIndex = i; 
                    break; 
                } 
            } 
 
            pFeatureLayer = (IFeatureLayer)pScene.get_Layer(iLayerIndex); 
 
            IFields pFields; 
            pFields = pFeatureLayer.FeatureClass.Fields; 
 
            dtGridView.ColumnCount = pFields.FieldCount; 
            for (int i = 0; i < pFields.FieldCount; i++) 
            { 
                string fldName; 
                fldName = pFields.get_Field(i).Name; 
                dtGridView.Columns[i].Name = fldName; 
 
            } 
 
            IFeatureCursor pFeatureCursor; 
            pFeatureCursor = pFeatureLayer.FeatureClass.Search(null, false); 
 
            long lTotalRecords = 1; 
            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 == "Shape") 
                    { 
                        fldValue[i] = Convert.ToString(pFeature.Shape.GeometryType); 
                    } 
                    else 
                        fldValue[i] = Convert.ToString(pFeature.get_Value(i)); 
                } 
                dtGridView.Rows.Add(fldValue); 
                pFeature = pFeatureCursor.NextFeature(); 
                lTotalRecords++; 
            } 
            toolStripStatusLabel1.Text = "共有" + Convert.ToString(lTotalRecords - 1) + "条记录"; 
             
        } 
 
        private void dtGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) 
        { 
            string FID; 
            FID = dtGridView.Rows[e.RowIndex].Cells[0].Value.ToString(); 
 
            if (FID == "") 
                return; 
            IActiveView pActiveView; 
            pActiveView = (IActiveView)pScene ; 
            pScene.ClearSelection(); 
            //pActiveView.Refresh(); 
 
            IQueryFilter pQueryFilter = new QueryFilterClass(); 
            pQueryFilter.WhereClause = "FID=" + FID; 
 
            IFeatureLayer pFeatureLayer; 
            pFeatureLayer = (IFeatureLayer)pScene.get_Layer(iLayerIndex); 
 
            IFeatureCursor pFeatureCursor; 
            pFeatureCursor = pFeatureLayer.Search(pQueryFilter, false); 
 
            IFeature pFeature; 
            pFeature = pFeatureCursor.NextFeature(); 
 
            pScene.SelectFeature(pFeatureLayer, pFeature); 
 
            //IPoint pPoint = new PointClass(); 
            //pPoint.X = (pFeature.Extent.XMin + pFeature.Extent.XMax) / 2; 
            //pPoint.Y = (pFeature.Extent.YMin + pFeature.Extent.YMax) / 2; 
 
            //pSceneControl.CenterAt(pPoint); 
 
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); 
        } 
    } 
}