Arcgis Engine1

public IMap m_Map;

 IFeatureLayer m_SelectedLyr = null;


    private void button1_Click(object sender, EventArgs e)
             {
                 if (treeList1.Selection.Count > 0)
               {
                string sObjectID = treeList1.Selection[0].GetValue(0).ToString();


                Form3 frm = new Form3();  
             


                //string sObjectID = lvi.Text;  
                IFeatureClass pFeaCls = m_SelectedLyr.FeatureClass;  
                IQueryFilter pQf = new QueryFilterClass();  
                pQf.WhereClause = pFeaCls.OIDFieldName + "=" + sObjectID;  


                IFeatureCursor pFeacur = pFeaCls.Update(pQf, false);
                IFeature pFea = pFeacur.NextFeature();  
                if (pFea != null)
                {
                    frm.m_Feature = pFea;
                      if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        IWorkspace pWks = (pFeaCls as IDataset).Workspace;  
                        IWorkspaceEdit pWksEdit = pWks as IWorkspaceEdit;  
                        pWksEdit.StartEditing(false);
                        pWksEdit.StartEditOperation();
                        bool blOK = true;  //设blOK为false
                        string sError = "";
                        try
                        {
                            for (int i = 0; i < frm.treeList1.Nodes.Count; i++)  
                            {
                                string sFldName = frm.treeList1.Nodes[i].GetValue(0).ToString();
                                string sFldValue = frm.treeList1.Nodes[i][1].ToString();  


                                int iFldIdx = pFea.Fields.FindField(sFldName);  
                                if (iFldIdx >= 0)
                                {
                                    pFea.set_Value(iFldIdx, sFldValue);  
                                }
                            }                  
                            pFea.Store();  
                            
                        }
                        catch (Exception ex)
                        {
                            sError = ex.Message;
                            blOK = false;
                        }
                        finally
                        {
                            if (blOK)
                                pWksEdit.StopEditOperation();  
                            else
                                pWksEdit.AbortEditOperation();  


                            pWksEdit.StopEditing(blOK);  


                            if (blOK)
                                RefreshDate(m_SelectedLyr);  
                            else
                                MessageBox.Show("保存失败,来自异常:" + sError);  
                        }
                    }
                }
            
             
            else
                MessageBox.Show("请选择要编辑的要素!");
             }


             }



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.esriSystem;

 public IFeature m_Feature; 

  private void Form3_Shown(object sender, EventArgs e)
        {
            for (int i = 0; i < m_Feature.Fields.FieldCount; i++)
            {
                IField pFld = m_Feature.Fields.get_Field(i);


                if (pFld.Editable == false)
                    continue;
                if ((pFld as IFieldEdit).Type == esriFieldType.esriFieldTypeOID)
                    continue;
                if ((pFld as IFieldEdit).Type == esriFieldType.esriFieldTypeGeometry)
                    continue;


                string sFldName = pFld.Name;
                string sFldValue = "";


                object pObj = m_Feature.get_Value(i);
                if (pObj != null)
                    sFldValue = pObj.ToString();
                treeList1.AppendNode(new object[] { sFldName, sFldValue }, null);


               
            }
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if (treeList1.Selection.Count > 0)
            {
                string sFidName = treeList1.FocusedNode.GetValue(0).ToString();
                string sFidValue = treeList1.FocusedNode.GetValue(1).ToString();


                //string sFldName = lvi.Text;  
                //string sFldValue = lvi.SubItems[1].Text;  


                Form4 frm = new Form4();
                frm.m_FieldName = sFidName;
                frm.m_FieldValue = sFidValue;


                if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    treeList1.BeginUpdate();
                    int num = treeList1.FocusedNode.Id;
                    treeList1.Nodes[num][1] = frm.m_FieldValue;
                    //lvi.SubItems[1].Text = frm.m_FieldValue;
                    treeList1.EndUpdate();
                }
                frm.Close();
            }
        }


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace 考核
{
    public partial class Form4 : Form
    {
        public string m_FieldName;
        public string m_FieldValue;
        public Form4()
        {
            InitializeComponent();
        }


        private void Form4_Shown(object sender, EventArgs e)
        {
            label1.Text = m_FieldName;
            textBox1.Text = m_FieldValue;
        }
        private void frmEditFieldValue_FormClosing(object sender, FormClosingEventArgs e)
        {
            m_FieldValue = textBox1.Text;
        }


        private void button1_Click(object sender, EventArgs e)
        {


        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值