On the basis of the above, ( easiest ArcGIS Engine application (on) )
The following simple code will be used to achieve feature class attributes of view.
A new form, and drag the DataGridView control from the toolbox to the form. Set the object's Dock property Fill.
Load time window for processing method of adding the code. When the form is loaded, the attribute information is read from the feature class layer data, and displays the DataGridView control.
FeatrAttributeTable.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ESRI.ArcGIS.DataSourcesFile; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Carto; using System.IO; using ESRI.ArcGIS.Controls; namespace SimpleArcEngineDemo { public partial classFeatrAttributeTable: Form { // declare the Map control variables. Private AxMapControl axMapControl; public FeatrAttributeTable () { the InitializeComponent (); } // overloaded constructor. public FeatrAttributeTable (AxMapControl pMapControl) { the InitializeComponent (); axMapControl = pMapControl; } Private void FeatrAttributeTable_Load ( Object SENDER, EventArgs E) { // get the first layer Layer 0 in the control map. ILayer pLayer = axMapControl.get_Layer (0 ); // the type pLayer cast IFeatureLayer. PFLayer = pLayer IFeatureLayer AS IFeatureLayer; // get class object feature pFC the IFeatureClass pFC = pFLayer.FeatureClass; // get the cursor. PFCursor = pFC.Search IFeatureCursor ( null , to false ); // get the first layer of the first element 0, element contains a plurality of attribute values. PFeature = pFCursor.NextFeature IFeature (); // Move the cursor to the next element of the result set and a return current feature here is assigned to the result returned pFeature // Create a table memory, and constructing the table structure, includes an attribute field and a data field . = PTable the DataTable new new the DataTable (); //New memory table DataColumn colName = new new DataColumn ( " Island name " ); // property field (attribute name) colName.DataType = System.Type.GetType ( " System.String " ); // data fields (data type) pTable. Columns.Add (colName); // added pTable in the DataColumn colArea = new new the DataColumn ( " area " ); // attribute field (attribute name) colArea.DataType = System.Type.GetType ( " System.String the " ); / / data field (data type) pTable.Columns.Add (colArea); // added in pTable // get a field named "CONTINENT" field in the index table memory. Hereinafter the same int indexOfName = pFC.FindField ( " CONTINENT " ); int indexOfName2 = pFC.FindField ( " SQMI " ); // when the element is not empty the while (! PFeature = null ) { // get the index number indexOfName string = pFeature.get_Value name (indexOfName) .ToString (); // get the corresponding attribute value field attribute String Area = pFeature.get_Value (indexOfName2) .ToString (); the DataRow PROWPTable.NewRow = (); // Create an empty row PROW [ 0 ] = name; // indexed by assigning PROW [ . 1 ] = Area; pTable.Rows.Add (PROW); // added to the pTable pFeature = pFCursor. NextFeature (); // move the cursor to the next element of the result set and a return current feature here is assigned to the result returned pFeature } dataGridView1.DataSource = pTable; // connect to the property sheet dataGridView1 control } } }
Form1.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using ESRI.ArcGIS.DataSourcesFile; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Carto; using System.IO; namespace SimpleArcEngineDemo { public partial class Form1 : Form { publicForm1 () { the InitializeComponent (); } /// <Summary> /// 2.2 ---- added shp data file is added to the map control ShapeFile. /// </ Summary> /// <param name = "SENDER"> </ param> /// <param name = "E"> </ param> Private void menuAddShp_Click ( Object SENDER, EventArgs E) { // step 1: create a workspace factory. PWorkspaceFactory = IWorkspaceFactory new new ShapefileWorkspaceFactory (); // File Filter, select the suffix .shp openFileDialog1.Filter = " ShapeFile files (* .shp) | *. // initial path setting file dialog openFileDialog1.InitialDirectory = @ " D: \ Data " ; // sample data folder openFileDialog1.Multiselect = to false ; // do not allow multiple selections the DialogResult DialogResult openFileDialog1.ShowDialog = (); / / open dialog IF (DialogResult =! DialogResult.OK) { return ; // returns the user does not select } // get the path corresponding to the file name, file name of the folder String pPath = openFileDialog1.FileName; // get the full path (path + file name) String= Path.GetDirectoryName pFolder (pPath); // get the file path (not including the file name) String pFileName = Path.GetFileName (pPath); // get the file name // Step 2: Open the file name of the corresponding working ShapeFile space. = PWorkspaceFactory.OpenFromFile pWorkspace1 the IWorkspace (pFolder, 0 ); // data directory IFeatureWorkspace pFeatureWorkspce = pWorkspace1 AS IFeatureWorkspace; // workspace elements of workspace turn into strong @ Step 3: Open the feature class. = PFC the IFeatureClass pFeatureWorkspce.OpenFeatureClass (pFileName); // Step 4: Create a feature class layer. PFLayer = IFeatureLayer new newFeatureLayerClass (); pFLayer.FeatureClass = pFC; pFLayer.Name = pFC.AliasName; // Step 5: associated layers and feature classes. PLayer = pFLayer ILayer AS ILayer; IMap PMAP = axMapControl1.Map; // Step 6: added to the map control. pMap.AddLayer (pLayer); axMapControl1.ActiveView.Refresh (); } /// <Summary> /// Add Layer by lyr file. /// </ Summary> /// <param name = "SENDER"> </ param> /// <param name = "E"> </ param> menuAddLyr_Click ( Object SENDER, EventArgs E) { // Step 1: navigate to a file open dialog lyr particular file. // file filter, select the suffix .lyr openFileDialog1.Filter = " the lyr file (* .lyr) | * .lyr " ; // set path initialization file dialog openFileDialog1.InitialDirectory = @ " D: \ the Data " ; openFileDialog1.Multiselect = false ; // do not allow multiple choice DialogResult pDialogResult openFileDialog1.ShowDialog = (); // open dialog box IF (pDialogResult =! DialogResult.OK) { return ; // returns the user does not select } String pFileName = openFileDialog1.FileName; // get the complete path (path + file name) // Step 2: loaded directly by the method (AddLayerFromFile) map control. axMapControl1.AddLayerFromFile (pFileName); axMapControl1.ActiveView.Refresh (); } Private void layer properties ToolStripMenuItem_Click ( Object SENDER, EventArgs E) { FeatrAttributeTable FRM = new new FeatrAttributeTable (axMapControl1); frm.ShowDialog (); } } }
Renderings:
Special mention:
IFeature pFeature = pFCursor.NextFeature();
pFeatureCursor feature class is a query returns a cursor (i.e., a pointer to the result set of search elements), pFeatureCursor.NextFeature () is about to move the cursor to the next element of the result set and a return current feature here is assigned to the result returned pFeature .
Thanks for watching! I am a novice GIS secondary development, if there is something wrong, please forgive me!