OK,So I am using a cursor to read a field value from a selected item in a shapefile. I need this value, so that I can update values in an external spreadsheet.After I read the value, I need to update it with a new value, which I am using another cursor for. For some reason, this isn't working. I think it's because I'm using more than one curosr on the same shapefile, but I can't say for sure.Here is my code when I am reading the shapefile:if (pLayer.Name == GlobalVars.TabletHydrantLayer)
{
featureSelection = (IFeatureSelection)pLayer;
selectionSet = (ISelectionSet2)featureSelection.SelectionSet;
if (selectionSet.Count == 1)
{
selectionSet.Search(null, false, out cursor);
featureCursor = (IFeatureCursor)cursor;
feature = featureCursor.NextFeature();
GlobalVars.SHPHydrantFacilityID = feature.get_Value(feature.Fields.FindField("FACILITYID")).ToString();
}
else
{
MessageBox.Show("Please make sure one feature is selected from the Tablet Hydrant layer " + GlobalVars.TabletHydrantLayer);
return;
}
}
And here is my code when I am trying to write to the same shapefile:if (pLayer.Name == GlobalVars.TabletHydrantLayer)
{
//Get the selected features of the current layer.
featureLayer = (IGeoFeatureLayer)pLayer;
featureSelection = (IFeatureSelection)featureLayer;
selectionSet = (ISelectionSet2)featureSelection.SelectionSet;
if (selectionSet.Count == 1)
{
//Create a feature cursor, so we can loop through all the selected features
selectionSet.Update(null, false, out cursor);
featureCursor2 = (IFeatureCursor)cursor;
//Start at the first selected feature.
feature = featureCursor2.NextFeature();
feature.set_Value(feature.Fields.FindField("FACILITYID"), "THIS IS A TEST");
featureCursor2.UpdateFeature(feature);
}
//Stop editing
m_editor.StopOperation("GIF Angle Update");
//Once all layers are processed, update the selected features on the map
ISelectionEvents selEvents = (ISelectionEvents)map;
selEvents.SelectionChanged();
MessageBox.Show("DONE");
The weirdest thing of all, is that when this code runs the first time (on a click event of a command button), then it doesn't work, but if I click it again, then it does.Any ideas as to what is going on?? If I don't even include the first bit of code where I read from the shapefile, it all works fine, but once I add it back, it doesn't work again. No error messages, it just doesn't work.I've been working on this for about 2 days and it's driving me insane!!!