InitializeComponent();
this.mMapControl = mapControl;
}
1111
窗体的 Load 事件:用于初始化 cboLayer,获取 MapControl 中的图层名称:
private void AttributeQueryForm_Load(object sender, EventArgs e)
{
//MapControl 中没有图层时返回
if (this.mMapControl.LayerCount <= 0)
return;
//获取 MapControl 中的全部图层名称,并加入 ComboBox
//图层
ILayer pLayer;
//图层名称
string strLayerName;
for (int i = 0; i < this.mMapControl.LayerCount; i++)
{
pLayer = this.mMapControl.get_Layer(i);
strLayerName = pLayer.Name;
//图层名称加入 cboLayer
this.cboLayer.Items.Add(strLayerName);
}
//默认显示第一个选项
this.cboLayer.SelectedIndex = 0;
}
在 CboLayer 的 SelectedIndexChanged 事件,当选中图层发生变化时,cboField 中的字段名
称重新获取:
private void cboLayer_SelectedIndexChanged(object sender, EventArgs e)
{
//获取 cboLayer 中选中的图层
mFeatureLayer = mMapControl.get_Layer(cboLayer.SelectedIndex) as IFeatureLayer;
IFeatureClass pFeatureClass = mFeatureLayer.FeatureClass;
//字段名称
string strFldName;
for (int i = 0; i < pFeatureClass.Fields.FieldCount; i++)
{
strFldName = pFeatureClass.Fields.get_Field(i).Name;
//图层名称加入 cboField
评论0