转自nimeila的回答 求C# ArcGIS Engine修改选中要素的属性,单要素都行
RLAlterFrm RLalter = new RLAlterFrm(); RLalter.ShowDialog(); string AlterID = RLalter.textBox1.Text; string AlterRP = RLalter.textBox2.Text; string AlterC = RLalter.textBox3.Text; axMapControl1.ClearLayers(); axMapControl1.Refresh(); try { string strFileName = Application.StartupPath + @"数据Roadlamp.mxd"; //在数据视图中加载地图,供查询操作 if (axMapControl1.CheckMxFile(strFileName)) { axMapControl1.LoadMxFile(strFileName); } else { MessageBox.Show("错误的数据路径:" + strFileName); } } catch (Exception ex) { MessageBox.Show("Error01 in MainForm.cs" + ex.Message); } axMapControl1.Refresh(); string strQK = RLalter.getQueryKey();//获取查询值 //找到图层 IFeatureLayer pfeaturelayer = new FeatureLayer(); pfeaturelayer = axMapControl1.get_Layer(0) as IFeatureLayer; //找到要素 IQueryFilter pQueryFilter = new QueryFilter(); pQueryFilter.WhereClause = "[RL_ID] = '" + strQK + "'"; IFeatureCursor pFeatureCur = pfeaturelayer.Search(pQueryFilter, false); IFeature pFeature = null; pFeature = pFeatureCur.NextFeature(); if (null == pFeature) { MessageBox.Show("对不起!该元素不存在"); } else { IFields pFields = pFeature.Fields; IFeatureClass pFeatureClass = pfeaturelayer.FeatureClass; //修改属性值 int field1 = pFields.FindField("RL_ID"); int field2 = pFields.FindField("RL_RP"); int field3 = pFields.FindField("RL_C"); pFeature.set_Value(field1, AlterID); pFeature.set_Value(field2, AlterRP); pFeature.set_Value(field3, AlterC); pFeature.Store(); MessageBox.Show("修改成功!","提示"); } }