求指出异常。被狠批了
求指出错误。被狠批了。
为什么字段选择的时候,会有多个重复的选项?我的数据没问题的。我保证。
为什么字段选择的时候,会有多个重复的选项?我的数据没问题的。我保证。
public partial class AttributeQueryForm : Form
{
//地图数据
private AxMapControl mMapControl;
//选中图层
private IFeatureLayer mFeatureLayer;
public AttributeQueryForm(AxMapControl mapControl)
{
InitializeComponent();
this.mMapControl = 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;
}
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
this.cboField.Items.Add(strFldName);
}
//默认显示第一个选项
this.cboField.SelectedIndex = 0;
}
private void btnOk_Click(object sender, EventArgs e)
{
//定义图层,要素游标,查询过滤器,要素
IFeatureLayer pFeatureLayer;
IFeatureCursor pFeatureCursor;
IQueryFilter pQueryFilter;
IFeature pFeature;
//获取图层
pFeatureLayer = this.mMapControl.Map.get_Layer(cboLayer.SelectedIndex) as IFeatureLayer;
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;