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)
{
}
}
}