通过ComBox查询属性表中的数据
来源:互联网 发布:淘宝美工招聘 编辑:程序博客网 时间:2024/06/05 00:21
效果图
此方法的缺陷在于,在用户不知道属性表中的字段和数据的情况下,不能实现查询操作;一次只能查询到一个要素,没办法选择两个或多个要素;一次只能选择一个图层中的一个要素,不能同时选择两个图层中的要素。在以后的学习中将解决此问题。
源码:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Geodatabase;using ESRI.ArcGIS.Geometry;namespace 通过ComBox查询属性表中的数据{ public partial class Form1 : Form { public Form1() { ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop); InitializeComponent(); } //选中图层 IFeatureLayer featureLayer; //当mapcontrol中的图层数据改变时,将所有图层名称加载到列表框中 private void axMapControl1_OnMapReplaced(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMapReplacedEvent e) { //清空列表框中已有的图层名称 comboBox1.Items.Clear(); //加载图层名称到列表框 IMap map = axMapControl1.Map; for (int i = 0; i < map.LayerCount; i++) { comboBox1.Items.Add(map.get_Layer(i).Name); } //列表框默认显示第一项 comboBox1.SelectedIndex = 0; } //当列表框中的文字改变时,在字段列表中列出当前文字所显示的图层的字段 private void comboBox1_TextChanged(object sender, EventArgs e) { //获取当前显示的图层 featureLayer = axMapControl1.get_Layer(comboBox1.SelectedIndex) as IFeatureLayer; //获取当前显示图层的特征类到特征类集中 IFeatureClass featureClass = featureLayer.FeatureClass; //清空字段列表中的内容 comboBox2.Items.Clear(); //字段名称 String fieldName = null; //遍历图层中的字段,加载到列表中 for (int i = 0; i < featureClass.Fields.FieldCount; i++) { fieldName = featureClass.Fields.get_Field(i).Name; comboBox2.Items.Add(fieldName); } //默认显示第一项 comboBox2.SelectedIndex = 0; } //点击查询按钮查询要素 private void button1_Click(object sender, EventArgs e) { //定义要素游标 IFeatureCursor featureCursor = null; //查询过滤器 IQueryFilter queryFilter = new QueryFilterClass(); //定义图层 IFeature feature = null; //点 IPoint point = new PointClass(); //获取范围 IEnvelope envelope = axMapControl1.ActiveView.Extent; //获取mapcontrol展示范围的中心位置 point.X = envelope.XMin + envelope.Width / 2; point.Y = envelope.YMin + envelope.Height / 2; if (axMapControl1.LayerCount <= 0) return; //获取图层,此句代码在ComBox1_TextChanged执行时已经执行过 //featurelayer = axMapControl1.get_Layer(comboBox1.SelectedIndex) as IFeatureLayer; //清除上次查询的结果 axMapControl1.Map.ClearSelection(); axMapControl1.ActiveView.Refresh(); //设置查询过滤条件,即查询语句 queryFilter.WhereClause = comboBox2.Text + "=" + textBox1.Text; //使用要素游标获取图层查询的结果 featureCursor = featureLayer.Search(queryFilter, true); //使用feature获取查询到的要素 feature = featureCursor.NextFeature(); //判断查询到的要素是否为空 if (feature != null) { //选择要素 axMapControl1.Map.SelectFeature(featureLayer, feature); //放大到要素 feature.Shape.Envelope.CenterAt(point); axMapControl1.Extent = feature.Shape.Envelope; } else { //没有得到feature的提示 MessageBox.Show("没有找到相关要素!", "提示"); } } }}
此方法的缺陷在于,在用户不知道属性表中的字段和数据的情况下,不能实现查询操作;一次只能查询到一个要素,没办法选择两个或多个要素;一次只能选择一个图层中的一个要素,不能同时选择两个图层中的要素。在以后的学习中将解决此问题。
- 通过ComBox查询属性表中的数据
- Extjs中的combox每个属性的意思
- MySQL 怎样通过相同字段,查询另一个表中的数据
- combox绑定数据修改表
- windows8中的ComBox控件的数据绑定
- WindForm中的Combox的数据绑定
- 通过linq汇总查询dataset 中的数据
- 通过XPath查询XML中的数据
- # combox绑定oracle查询的数据集(列)
- EXCEL-VBA:通过SQL查询数据Sheet中的数据
- 创建一个指向本地数据库的 dblink,并通过 dblink 查询一个表中的数据
- 查询属性结构数据
- mfc 可编辑combox不可用时,背景变黑,通过修改属性解决
- extjs Combox 调用数据
- EXT3.2 combox属性说明
- WPF 中通过ComBox的改变来改变Frame中的子.xaml项 View-ViewModel模式
- C# combox下拉模糊查询
- 根据一个表中的字段属性名称作为查询条件来批量修改该表中数据
- MATLAB帮助文档_MATLAB产品_MATLAB Products
- 一个outerclick解决方案,看jquery里面的one,事件,和特效
- 变量替换与扩展
- MySQL单机多实例配置
- 用下流的姿态枪毙了爱情:伤感日志
- 通过ComBox查询属性表中的数据
- MATLAB帮助文档_工具箱_Toolboxes
- 基于主成分的图像处理
- googlemap 安装到手机上!!!!
- UML 用例图
- 办公室打印服务器方案
- uva_340 - Master-Mind Hints
- Linux中的各种Signal(Process XXX terminated by signal (X))
- 寂寞的眼泪,孤独做主:伤感QQ个性日志