AnsweredAssumed Answered

Getting the OID from a selected feature

Question asked by ryan.hawkins on Feb 4, 2013
Latest reply on Feb 6, 2013 by ryan.hawkins
I am trying to get the OID of the selected feature to display in textBox2. I am getting an error that says ArcGIS Desktop has encountered a serious application error and is unable to continue. It was strange I got it to work once but I had to continue through an error screen and havent been able to reenact the scenario since. Now it merely crashes everytime. I have made sure a feature is selected as well. I had copied the code in GetSelectedValues() so I am guessing it is how I am initializing the featurelayer. I am new to developing so any suggestions will be greatly appreciated!
    public void StartButton_Click(object sender, EventArgs e)
            IApplication app = (IApplication)this.Hook;
            IMxDocument mapDoc = (IMxDocument)app.Document;
            IFeatureLayer featureLayer = (IFeatureLayer)mapDoc.SelectedLayer;
    private void GetSelectedValues(IFeatureLayer featureLayer)
            IFeatureSelection featureSelection = featureLayer as IFeatureSelection;
            ISelectionSet selectionSet = featureSelection.SelectionSet;

            ICursor cursor;
            selectionSet.Search(null, false, out cursor);

            IRow row = cursor.NextRow();
            textBox2.Text = row.OID.ToString();

            while (cursor != null)
                row = cursor.NextRow();