ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Editing Namespace / EditOperation.IEditContext Interface / Invalidate Method / Invalidate(Row) Method
The featue/row to invalidate.
Example

In This Topic
    Invalidate(Row) Method
    In This Topic
    Invalidates a feature/row.
    Syntax
    void Invalidate( 
       Row row
    )
    Overloads Sub Invalidate( _
       ByVal row As Row _
    ) 

    Parameters

    row
    The featue/row to invalidate.
    Example
    Creating a Row
    public async Task CreatingARow()
    {
      string message = String.Empty;
      bool creationResult = false;
      EditOperation editOperation = new EditOperation();
    
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
    
        using (Geodatabase geodatabase = new Geodatabase(
          new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (Table enterpriseTable = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.piCIPCost"))
        {
    
          //var geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(uri)) for a File GDB
          //
          //var shapeFileConnPath = new FileSystemConnectionPath(uri, FileSystemDatastoreType.Shapefile);
          //var shapefile = new FileSystemDatastore(shapeFileConnPath);
          //var table = shapefile.OpenDataset<Table>(strShapeFileName); for a Shape file
    
          //declare the callback here. We are not executing it ~yet~
          editOperation.Callback(context =>
          {
            TableDefinition tableDefinition = enterpriseTable.GetDefinition();
            int assetNameIndex = tableDefinition.FindField("ASSETNA");
    
            using (RowBuffer rowBuffer = enterpriseTable.CreateRowBuffer())
            {
              // Either the field index or the field name can be used in the indexer.
              rowBuffer[assetNameIndex] = "wMain";
              rowBuffer["COST"] = 700;
              rowBuffer["ACTION"] = "Open Cut";
    
              // subtype value for "Abandon".
              rowBuffer[tableDefinition.GetSubtypeField()] = 3;
    
              using (Row row = enterpriseTable.CreateRow(rowBuffer))
              {
                // To Indicate that the attribute table has to be updated.
                context.Invalidate(row);
              }
            }
          }, enterpriseTable);
    
          try
          {
            creationResult = editOperation.Execute();
            if (!creationResult) message = editOperation.ErrorMessage;
          }
          catch (GeodatabaseException exObj)
          {
            message = exObj.Message;
          }
        }
      });
    
      if (!string.IsNullOrEmpty(message))
        MessageBox.Show(message);
    
    }
    Modifying a Row
    public async Task ModifyingARow()
    {
      string message = String.Empty;
      bool modificationResult = false;
    
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (Table enterpriseTable = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.piCIPCost"))
        {
          //var geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(uri)) for a File GDB
          //
          //var shapeFileConnPath = new FileSystemConnectionPath(uri, FileSystemDatastoreType.Shapefile);
          //var shapefile = new FileSystemDatastore(shapeFileConnPath);
          //var table = shapefile.OpenDataset<Table>(strShapeFileName); for a Shape file
    
          EditOperation editOperation = new EditOperation();
          editOperation.Callback(context =>
          {
            QueryFilter openCutFilter = new QueryFilter { WhereClause = "ACTION = 'Open Cut'" };
    
            using (RowCursor rowCursor = enterpriseTable.Search(openCutFilter, false))
            {
              TableDefinition tableDefinition = enterpriseTable.GetDefinition();
              int subtypeFieldIndex = tableDefinition.FindField(tableDefinition.GetSubtypeField());
    
              while (rowCursor.MoveNext())
              {
                using (Row row = rowCursor.Current)
                {
                  // In order to update the Map and/or the attribute table.
                  // Has to be called before any changes are made to the row.
                  context.Invalidate(row);
    
                  row["ASSETNA"] = "wMainOpenCut";
    
                  if (Convert.ToDouble(row["COST"]) > 700)
                  {
                    // Abandon asset if cost is higher than 700 (if that is what you want to do).
                    row["ACTION"] = "Open Cut Abandon";
                    row[subtypeFieldIndex] = 3; //subtype value for "Abandon"   
                  }
    
                  //After all the changes are done, persist it.
                  row.Store();
    
                  // Has to be called after the store too.
                  context.Invalidate(row);
                }
              }
            }
          }, enterpriseTable);
    
          try
          {
            modificationResult = editOperation.Execute();
            if (!modificationResult) message = editOperation.ErrorMessage;
          }
          catch (GeodatabaseException exObj)
          {
            message = exObj.Message;
          }
        }
      });
    
      if (!string.IsNullOrEmpty(message))
        MessageBox.Show(message);
    }
    Modifying a Row
    public async Task ModifyingARow()
    {
      string message = String.Empty;
      bool modificationResult = false;
    
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (Table enterpriseTable = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.piCIPCost"))
        {
          //var geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(uri)) for a File GDB
          //
          //var shapeFileConnPath = new FileSystemConnectionPath(uri, FileSystemDatastoreType.Shapefile);
          //var shapefile = new FileSystemDatastore(shapeFileConnPath);
          //var table = shapefile.OpenDataset<Table>(strShapeFileName); for a Shape file
    
          EditOperation editOperation = new EditOperation();
          editOperation.Callback(context =>
          {
            QueryFilter openCutFilter = new QueryFilter { WhereClause = "ACTION = 'Open Cut'" };
    
            using (RowCursor rowCursor = enterpriseTable.Search(openCutFilter, false))
            {
              TableDefinition tableDefinition = enterpriseTable.GetDefinition();
              int subtypeFieldIndex = tableDefinition.FindField(tableDefinition.GetSubtypeField());
    
              while (rowCursor.MoveNext())
              {
                using (Row row = rowCursor.Current)
                {
                  // In order to update the Map and/or the attribute table.
                  // Has to be called before any changes are made to the row.
                  context.Invalidate(row);
    
                  row["ASSETNA"] = "wMainOpenCut";
    
                  if (Convert.ToDouble(row["COST"]) > 700)
                  {
                    // Abandon asset if cost is higher than 700 (if that is what you want to do).
                    row["ACTION"] = "Open Cut Abandon";
                    row[subtypeFieldIndex] = 3; //subtype value for "Abandon"   
                  }
    
                  //After all the changes are done, persist it.
                  row.Store();
    
                  // Has to be called after the store too.
                  context.Invalidate(row);
                }
              }
            }
          }, enterpriseTable);
    
          try
          {
            modificationResult = editOperation.Execute();
            if (!modificationResult) message = editOperation.ErrorMessage;
          }
          catch (GeodatabaseException exObj)
          {
            message = exObj.Message;
          }
        }
      });
    
      if (!string.IsNullOrEmpty(message))
        MessageBox.Show(message);
    }
    Modifying a Feature
    public async Task ModifyingAFeature()
    {
      string message = String.Empty;
      bool modificationResult = false;
    
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (FeatureClass enterpriseFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.FacilitySite"))
        {
    
          //var geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(uri)) for a File GDB
          //
          //var shapeFileConnPath = new FileSystemConnectionPath(uri, FileSystemDatastoreType.Shapefile);
          //var shapefile = new FileSystemDatastore(shapeFileConnPath);
          //var table = shapefile.OpenDataset<Table>(strShapeFileName); for a Shape file
    
          FeatureClassDefinition facilitySiteDefinition = enterpriseFeatureClass.GetDefinition();
    
          int ownTypeIndex = facilitySiteDefinition.FindField("OWNTYPE");
          int areaIndex = facilitySiteDefinition.FindField(facilitySiteDefinition.GetAreaField());
    
          EditOperation editOperation = new EditOperation();
          editOperation.Callback(context =>
          {
            QueryFilter queryFilter = new QueryFilter { WhereClause = "FCODE = 'Hazardous Materials Facility' AND OWNTYPE = 'Private'" };
    
            using (RowCursor rowCursor = enterpriseFeatureClass.Search(queryFilter, false))
            {
              while (rowCursor.MoveNext())
              {
                using (Feature feature = (Feature)rowCursor.Current)
                {
                  // In order to update the Map and/or the attribute table.
                  // Has to be called before any changes are made to the row
                  context.Invalidate(feature);
    
                  // Transfer all Hazardous Material Facilities to the City.
                  feature[ownTypeIndex] = "Municipal";
    
                  if (Convert.ToDouble(feature[areaIndex]) > 50000)
                  {
                    // Set the Shape of the feature to whatever you need.
                    List<Coordinate2D> newCoordinates = new List<Coordinate2D>
                    {
                      new Coordinate2D(1021570, 1880583),
                      new Coordinate2D(1028730, 1880994),
                      new Coordinate2D(1029718, 1875644),
                      new Coordinate2D(1021405, 1875397)
                    };
    
                    feature.SetShape(new PolygonBuilderEx(newCoordinates).ToGeometry());
                  }
    
                  feature.Store();
    
                  // Has to be called after the store too
                  context.Invalidate(feature);
                }
              }
            }
          }, enterpriseFeatureClass);
    
          try
          {
            modificationResult = editOperation.Execute();
            if (!modificationResult) message = editOperation.ErrorMessage;
          }
          catch (GeodatabaseException exObj)
          {
            message = exObj.Message;
          }
        }
      });
    
      if (!string.IsNullOrEmpty(message))
        MessageBox.Show(message);
    }
    Deleting a Row/Feature
    public async Task DeletingARowOrFeature()
    {
      string message = String.Empty;
      bool deletionResult = false;
    
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        using (Table enterpriseTable = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.piCIPCost"))
        {
          //var geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(uri)) for a File GDB
          //
          //var shapeFileConnPath = new FileSystemConnectionPath(uri, FileSystemDatastoreType.Shapefile);
          //var shapefile = new FileSystemDatastore(shapeFileConnPath);
          //var table = shapefile.OpenDataset<Table>(strShapeFileName); for a Shape file
    
          EditOperation editOperation = new EditOperation();
          editOperation.Callback(context =>
          {
            QueryFilter openCutFilter = new QueryFilter { WhereClause = "ACTION = 'Open Cut'" };
    
            using (RowCursor rowCursor = enterpriseTable.Search(openCutFilter, false))
            {
              while (rowCursor.MoveNext())
              {
                using (Row row = rowCursor.Current)
                {
                  // In order to update the Map and/or the attribute table. Has to be called before the delete.
                  context.Invalidate(row);
    
                  row.Delete();
                }
              }
            }
          }, enterpriseTable);
    
          try
          {
            deletionResult = editOperation.Execute();
            if (!deletionResult) message = editOperation.ErrorMessage;
          }
          catch (GeodatabaseException exObj)
          {
            message = exObj.Message;
          }
        }
      });
    
      if (!string.IsNullOrEmpty(message))
        MessageBox.Show(message);
    }
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also