ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Core.Data Namespace / Table Class / Select(QueryFilter,SelectionType,SelectionOption) Method
A filter used when querying the table.
Specifies whether the selection should be based on SelectionType.ObjectID or SelectionType.GlobalID.
Specifies the content of the Selection.
Example

In This Topic
    Select(QueryFilter,SelectionType,SelectionOption) Method
    In This Topic
    Creates a selection of specific rows in this Table that satisfy the criteria set in the queryFilter. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    queryFilter
    A filter used when querying the table.
    selectionType
    Specifies whether the selection should be based on SelectionType.ObjectID or SelectionType.GlobalID.
    selectionOption
    Specifies the content of the Selection.

    Return Value

    A new Selection instance that satisfies the criteria set in queryFilter and selectionOption.
    Exceptions
    ExceptionDescription
    If queryFilter is an instance of SpatialQueryFilter, either both the 'FilterGeometry' and 'SpatialRelationship' properties are set or both are not set. Otherwise, an ArgumentException will be raised.
    selectionType or selectionOption is invalid.

    selectionType is specified as SelectionType.GlobalID and the underlying data store of this table or feature class is not an enterprise geodatabase.

    -or-

    The underlying data store (e.g., a Database) does not support this operation.

    The table or feature class is not global ID enabled.
    A geodatabase-related exception has occurred.
    Remarks
    In order to specify selectionType as SelectionType.GlobalID, two preconditions must be satisfied:
    1. The underlying data store of this table or feature class must be an enterprise geodatabase.
    2. The table or feature class must have global IDs.
    Example
    Selecting Rows from a Table
    public async Task SelectingRowsFromATable()
    {
      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"))
        {
          QueryFilter anotherQueryFilter = new QueryFilter { WhereClause = "FLOOR = 1 AND WING = 'E'" };
    
          // For Selecting all matching entries.
          using (Selection anotherSelection = enterpriseTable.Select(anotherQueryFilter, SelectionType.ObjectID, SelectionOption.Normal))
          {
          }
    
          // This can be used to get one record which matches the criteria. No assumptions can be made about which record satisfying the criteria is selected.
          using (Selection onlyOneSelection = enterpriseTable.Select(anotherQueryFilter, SelectionType.ObjectID, SelectionOption.OnlyOne))
          {
          }
    
          // This can be used to obtain a empty selction which can be used as a container to combine results from different selections.
          using (Selection emptySelection = enterpriseTable.Select(anotherQueryFilter, SelectionType.ObjectID, SelectionOption.Empty))
          {
          }
    
          // If you want to select all the records in a table.
          using (Selection allRecordSelection = enterpriseTable.Select(null, SelectionType.ObjectID, SelectionOption.Normal))
          {
          }
        }
      });
    }
    Selecting Features from a FeatureClass
    public async Task SelectingFeaturesFromAFeatureClass()
    {
      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"))
        {
          List<Coordinate2D> newCoordinates = new List<Coordinate2D>
          {
            new Coordinate2D(1021570, 1880583),
            new Coordinate2D(1028730, 1880994),
            new Coordinate2D(1029718, 1875644),
            new Coordinate2D(1021405, 1875397)
          };
    
          SpatialQueryFilter spatialFilter = new SpatialQueryFilter
          {
            WhereClause = "FCODE = 'Park'",
            FilterGeometry = new PolygonBuilderEx(newCoordinates).ToGeometry(),
            SpatialRelationship = SpatialRelationship.Crosses
          };
    
          // For Selecting all matching entries.
          using (Selection anotherSelection = enterpriseFeatureClass.Select(spatialFilter, SelectionType.ObjectID, SelectionOption.Normal))
          {
          }
    
          // This can be used to get one record which matches the criteria. No assumptions can be made about which record satisfying the 
          // criteria is selected.
          using (Selection onlyOneSelection = enterpriseFeatureClass.Select(spatialFilter, SelectionType.ObjectID, SelectionOption.OnlyOne))
          {
          }
    
          // This can be used to obtain a empty selction which can be used as a container to combine results from different selections.
          using (Selection emptySelection = enterpriseFeatureClass.Select(spatialFilter, SelectionType.ObjectID, SelectionOption.Empty))
          {
          }
    
          // If you want to select all the records in a table.
          using (Selection allRecordSelection = enterpriseFeatureClass.Select(null, SelectionType.ObjectID, SelectionOption.Normal))
          {
          }
        }
      });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also