How to check if a table row is selected or not with RowCursor in ArcGIS Pro SDK?

305
1
Jump to solution
01-04-2021 03:19 PM
Amadeus111
Occasional Contributor II

Is there way to check if a row is selected when using row by row cursor 

using (ArcGIS.Core.Data.Table GNISFTable = (GNISFLayer as FeatureLayer).GetTable())
                {

                    using (RowCursor rowCursor = GNISFLayer.Search())
                    {
                        while (rowCursor.MoveNext())
                        {
                            using (ArcGIS.Core.Data.Row row = rowCursor.Current)
                            //If row is not selected skip
                            {
                                fType =  row["FEATURE_CLASS"].ToString();
                                state = row["STATE_ALPHA"].ToString();
                                county = row["COUNTY_NAME"].ToString();
                                quad = row["MAP_NAME"].ToString();
       
                            };
                        }
                    }
                }

 

0 Kudos
1 Solution

Accepted Solutions
RichRuh
Esri Regular Contributor

Hi Oguz,

You can obtain a Selection object from the feature layer, and create a RowCursor based on that.

using (ArcGIS.Core.Data.Selection selectedFeatures = (GNISFLayer as FeatureLayer).GetSelection())
{
  using (RowCursor rowCursor = selectedFeatures.Search(null))
  {
    while (rowCursor.MoveNext())
    {
      using (ArcGIS.Core.Data.Row row = rowCursor.Current)
      //Only selected records will be returned
      {
        fType =  row["FEATURE_CLASS"].ToString();
        state = row["STATE_ALPHA"].ToString();
        county = row["COUNTY_NAME"].ToString();
        quad = row["MAP_NAME"].ToString();
      }
    }
  }
}

View solution in original post

1 Reply
RichRuh
Esri Regular Contributor

Hi Oguz,

You can obtain a Selection object from the feature layer, and create a RowCursor based on that.

using (ArcGIS.Core.Data.Selection selectedFeatures = (GNISFLayer as FeatureLayer).GetSelection())
{
  using (RowCursor rowCursor = selectedFeatures.Search(null))
  {
    while (rowCursor.MoveNext())
    {
      using (ArcGIS.Core.Data.Row row = rowCursor.Current)
      //Only selected records will be returned
      {
        fType =  row["FEATURE_CLASS"].ToString();
        state = row["STATE_ALPHA"].ToString();
        county = row["COUNTY_NAME"].ToString();
        quad = row["MAP_NAME"].ToString();
      }
    }
  }
}