I'm new to C#, developing and programming in general but I'm trying to build a form that will write to a new (initially blank) point feature class file and add records (or rows) with the data in the form. The SHAPE info will come from another feature class existing in the table of contents.
I'm having trouble adding records with data. In this case, my form is not fully developed and will simply be adding data to the 'Team' field and to the SHAPE field. But, I think something is not right with the following code:
//Update attributes using form controls
IFeature pNewFeat = pTeamInfo.FeatureClass.CreateFeature();
pNewFeat.Shape = pFeatRow.ShapeCopy;
pNewFeat.set_Value(pFeatRow.Fields.FindField("Team"), txtTeam.Text);
pNewFeat.Store();
Note, the entire frm Code is included below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.ArcMapUI;
using System.Security.Principal;
using ESRI.ArcGIS.Editor;
using ESRI.ArcGIS.Framework;
namespace v1._02
{
public partial class frmPickPeak : Form
{
private IMxDocument pMxDoc;
private IMap pMap;
private IFeatureLayer pPeakInfo;
private IFeatureLayer pTeamInfo;
private IFeature pFeatRow;
public frmPickPeak()
{
InitializeComponent();
this.Load += new EventHandler(frmEditer_Load);
btnRegister.Click += new EventHandler(btnRegister_Click);
btnExit.Click += new EventHandler(btnExit_Click);
}
private void frmEditer_Load(object sender, EventArgs e)
{
//get MxDoc from Application, get Map from MxDoc
pMxDoc = cmdOnTarget.g_application.Document as IMxDocument;
pMap = pMxDoc.FocusMap;
//get cursor of selected row from FeatureSelection SelectionSet
pPeakInfo = cmdOnTarget.getLayerByToc("PeakInfo");
pTeamInfo = cmdOnTarget.getLayerByToc("TeamInfo");
IFeatureSelection pFeatSel = pPeakInfo as IFeatureSelection;
//Get row from Cursor
pFeatRow = pPeakInfo.FeatureClass.GetFeature(pFeatSel.SelectionSet.IDs.Next());
//Update form controls using row attributes
lblPeak.Text = pFeatRow.get_Value(pFeatRow.Fields.FindField("Name")).ToString();
lblLat.Text = pFeatRow.get_Value(pFeatRow.Fields.FindField("Lat")).ToString();
lblLong.Text = pFeatRow.get_Value(pFeatRow.Fields.FindField("Long")).ToString();
}
private void btnRegister_Click(object sender, EventArgs e)
{
//Change mouse cursor to hourglass
IMouseCursor pMouseCur = new MouseCursor();
pMouseCur.SetCursor(2);
//Start Editing
IDataset pDataset = pPeakInfo as IDataset;
IEditor pEditor = cmdOnTarget.g_application.FindExtensionByName("ESRI Object Editor") as IEditor;
if (pEditor.EditState != esriEditState.esriStateEditing)
{
pEditor.StartEditing(pDataset.Workspace);
}
//Update attributes using form controls
pFeatRow.set_Value(pFeatRow.Fields.FindField("Picked"), "yes");
pFeatRow.Store();
//Stop editing and save edits
pEditor.StopEditing(true);
//Edit the feature class entitled: TeamInfo
IDataset pDataset2 = pTeamInfo as IDataset;
IEditor pEditor2 = cmdOnTarget.g_application.FindExtensionByName("ESRI Object Editor") as IEditor;
if (pEditor2.EditState != esriEditState.esriStateEditing)
{
pEditor2.StartEditing(pDataset2.Workspace);
}
//Update attributes using form controls
IFeature pNewFeat = pTeamInfo.FeatureClass.CreateFeature();
pNewFeat.Shape = pFeatRow.ShapeCopy;
pNewFeat.set_Value(pFeatRow.Fields.FindField("Team"), txtTeam.Text);
pNewFeat.Store();
pEditor.StopEditing(true);
this.Dispose(); //Dispose (exit) form
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Dispose();
}
}
}
I'm not really sure what the problem is. A new record is being written, but the Team field is not being updated. Likewise, copies of the new points do not show up in ArcMap so I doubt the SHAPE info is copying. Please help, and I'll try to clarify anything if this thread is not clear.
Thanks
Scott