TOCControl 打开图层属性表(转)
Posted hl137510705
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TOCControl 打开图层属性表(转)相关的知识,希望对你有一定的参考价值。
首先添加一个新的windows窗体frmAttribute,在上面添加个datagridview控件,用来显示图层属性! 定义frmAttribute中的全局变量:
private ILayer pLayer;;//打开属性表的图层 private IFeatureLayer pFeatureLayer; private IFeatureClass pFeatureClass;
private ILayerFields pLayerFields;
修改构造函数,传入要打开属性表的图层:
public frmAttribute( ILayer pLyr) { InitializeComponent(); // m_MapControl = pMapControl; pLayer = pLyr; }
在右键菜单的打开属性表选项单击事件总打开frmAttribute窗口:
private void AttributesToolStripMenuItem_Click(object sender, EventArgs e) { frmAttribute newFA = new frmAttribute( p_Layer);//传入图层,在右击事件里返回的图层 newFA.Show(); }
窗机加载时读取信息:
private void frmAttribute_Load(object sender, EventArgs e)
{ try { pFeatureLayer = pLayer as IFeatureLayer; pFeatureClass = pFeatureLayer.FeatureClass; pLayerFields = pFeatureLayer as ILayerFields; DataSet ds = new DataSet("dsTest"); DataTable dt = new DataTable(pFeatureLayer.Name); DataColumn dc = null; for (int i = 0; i < pLayerFields.FieldCount; i++) { dc = new DataColumn(pLayerFields.get_Field(i).Name); //if (pLayerFields.get_Field(i).Editable == true) // dc.ReadOnly = false; //else // dc.ReadOnly = true; dt.Columns.Add(dc); dc = null; } IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false); IFeature pFeature = pFeatureCursor.NextFeature(); while (pFeature != null) { DataRow dr = dt.NewRow(); for (int j = 0; j < pLayerFields.FieldCount; j++) { if (pLayerFields.FindField(pFeatureClass.ShapeFieldName) == j) { dr[j] = pFeatureClass.ShapeType.ToString(); } else { dr[j] =pFeature.get_Value(j); } } dt.Rows.Add(dr); pFeature = pFeatureCursor.NextFeature(); } dataGridView1.DataSource = dt; } catch (Exception exc) { MessageBox.Show("读取属性表失败:" + exc.Message); this.Dispose(); } finally { //this.Close(); } }
更多GIS开发相关问题请加入 GIS开发学习QQ交流群 192251607 共同交流学习!
以上是关于TOCControl 打开图层属性表(转)的主要内容,如果未能解决你的问题,请参考以下文章