Open the Attribute Table of the element layer

Source: Internet
Author: User
I recently read other code written by my peers using VB on the website about opening the element layer Attribute Table. I changed it and wrote it in C, I hope it will be helpful for everyone to learn and use it!

Private void OpenAttribute_Load (object sender, System. EventArgs e)
{
// Obtain the element layer interface
IFeatureLayer pFeatLyr = (IFeatureLayer) axMapControl1.get _ Layer (0 );
// Query the ILayerFields Interface
ILayerFields pFeatLyrFields = (ILayerFields) pFeatLyr;
IFeatureClass pFeatCls = pFeatLyr. FeatureClass;

DataSet myDataset = new DataSet ("Test ");
DataTable pTable = new DataTable (pFeatLyr. Name );
For (int n = 0; n <pFeatLyrFields. FieldCount-1; n ++)
{
DataColumn pTableCol = new DataColumn (pFeatLyrFields. get_Field (n). Name );
PTable. Columns. Add (pTableCol );
PTableCol = null;
}
IFeatureCursor pFeatCursor = pFeatCls. Search (null, false );
IFeature pFeat = pFeatCursor. NextFeature ();
While (pFeat! = Null)
{
DataRow pTableRow = pTable. NewRow ();
For (int I = 0; I <pFeatLyrFields. FieldCount-1; I ++)
{
If (pFeatLyrFields. FindField (pFeatCls. ShapeFieldName) = I)
{
PTableRow [I] = pFeatCls. ShapeType. ToString ();
}
Else
{
PTableRow [I] = pFeat. get_Value (I). ToString ();
}
}
PTable. Rows. Add (pTableRow );
PFeat = pFeatCursor. NextFeature ();
}
MyDataset. Tables. Add (pTable );
DataGrid1.DataSource = myDataset;
DataGrid1.DataMember = pFeatLyr. Name;
}

// Select and edit the Attribute Table
Private void datagrid=mousedown (object sender, System. Windows. Forms. MouseEventArgs e)
{
DataGrid myGrid = (DataGrid) sender;
DataGrid. HitTestInfo myHitTestInfo = myGrid. HitTest (e. X, e. Y );
String message = "You clicked ";

Switch (myHitTestInfo. Type)
{
Case System. Windows. Forms. DataGrid. HitTestType. None:
Message + = "the background .";
Break;
Case System. Windows. Forms. DataGrid. HitTestType. Cell:
Message + = "cell at row" + myHitTestInfo. Row + ", col" + myHitTestInfo. Column;
Break;
Case System. Windows. Forms. DataGrid. HitTestType. ColumnHeader:
Message + = "the column header for column" + myHitTestInfo. Column;
Break;
Case System. Windows. Forms. DataGrid. HitTestType. RowHeader:
Message + = "the row header for row" + myHitTestInfo. Row;
Break;
Case System. Windows. Forms. DataGrid. HitTestType. ColumnResize:
Message + = "the column resizer for column" + myHitTestInfo. Column;
Break;
Case System. Windows. Forms. DataGrid. HitTestType. RowResize:
Message + = "the row resizer for row" + myHitTestInfo. Row;
Break;
Case System. Windows. Forms. DataGrid. HitTestType. Caption:
Message + = "the caption ";
Break;
Case System. Windows. Forms. DataGrid. HitTestType. ParentRows:
Message + = "the parent row ";
Break;
}

Console. WriteLine (message );

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.