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 共同交流学习!

 

转载于:https://www.cnblogs.com/hl137510705/p/9266587.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值