Here is another example that uses the selection from one feature class to select features in another feature class.
//"SelectByLocation" - Select Counties based on selected State polygon
Layout layout = LayoutView.Active.Layout;
await QueuedTask.Run(() =>
{
MapFrame mf = layout.FindElement("Map Frame") as MapFrame;
Map m = mf.Map;
//Select a single state polygon
FeatureLayer fl1 = m.FindLayers("State_Polygons").First() as FeatureLayer;
QueryFilter queryFilter = new QueryFilter();
string whereClause = "State_Name = 'Rhode Island'";
queryFilter.WhereClause = whereClause;
//Use a cursor to get to a feature's geometry
using (ArcGIS.Core.Data.RowCursor rowCursor = fl1.Search(queryFilter))
{
//Grab the first record (and hopefully only record)
while (rowCursor.MoveNext())
{
//Grab the features geometry
Feature feature = rowCursor.Current as Feature;
Geometry geo = feature.GetShape();
//Set up a spatial query
var spatialQuery = new SpatialQueryFilter()
{ FilterGeometry = geo, SpatialRelationship = SpatialRelationship.Intersects };
//Reference county layer and apply spatial query
FeatureLayer fl2 = m.FindLayers("Counties").First() as FeatureLayer;
fl2.Select(spatialQuery);
}
}
});