I Have code

   ISelectionSet pSelectionSet;
   layer = AxMapControl1.get_Layer(0);
   pFeatSel = (IFeatureSelection)layer
   pSelectionSet = pFeatSel.SelectionSet;
   ITable table = pSelectionSet  as ITable;

How to convert selection to a table?

  • Your code makes no sense as ISelectionSet is not implemented by Table. When you say table do you mean FeatureClass? Are you trying to save out a sub-set of your data or do you want to create a cursor to step over the selection?
    – Hornbydd
    Jan 30, 2015 at 11:54

1 Answer 1



If you want to get the ITable the selected items are in then look at ISelectionSet.Target.

If you want to iterate through the selected items, then loop through the enumeration provided by ISelectionSet.IDs e.g.:

var tbl = pSelectionSet.Target;
var ids = pSelectionSet.IDs;
for( int id = ids.Next(); id >= 0; id = ids.Next() ) {
    var row = tbl.GetRow(id);

If you want to change what is selected then you need to use something like:

var ids = new int[x];
// ... populate ids w/ OID's to add/remove
var gdb = new GeoDatabaseHelperClass();  // .NET COM safe manipulation of selection set
gdb.RemoveList(pFeatSel.SelectionSet, ref ids);
// or
gdb.AddList(pFeatSel.SelectionSet, ref ids);
  • The answer is less clear. What do you want here for( int id = ids.Next(); id >= 0; id = ids.Next() ) { var row = tbl.GetRow(id); ... }
    – Mr.Phuong
    Jan 31, 2015 at 1:20
  • It wasn't clear from your original post what you wanted the ITable for, so I guessed and gave examples of the most common scenarios of working with ISelectionSet. Jan 31, 2015 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.