Programmatically add selected feature to editSelection

2535
3
Jump to solution
08-07-2014 12:42 PM
KennethRenner
New Contributor

I have created a button that creates a feature at a current GPS location.

I can create the feature easy enough and set it as selected.

Immediately after it is created I want it to be added to the Edit Selection so the user doesn't have to manually use the editor tool to select it.

Thanks for any help you can give me.

                           //Start Edit Session

                            UID uid = new UIDClass();

                            uid.Value = "esriEditor.Editor";

                            IEditor editor = cls_globals.M_IAPPLICATION.FindExtensionByCLSID(uid) as IEditor;                           

                            editor.StartOperation();

                            IFeatureClass pfcl = cls_globals.GetIFeatureClass(cls_globals.CURRENT_POLE_LAYER);

                            IFeature ftr = pfcl.CreateFeature();

                            ftr.Shape = cls_globals.CURRENT_GPS_POINT_GEOMETRY;

                            ILayer lyr = (ILayer)cls_globals.GetFeatureLayer(cls_globals.CURRENT_POLE_LAYER);

                            IEditTemplate editTemplate = GetEditTemplate(lyr);

                            editTemplate.SetDefaultValues(ftr);                          

                            ftr.Store();                         

                            editor.Display.Invalidate(ftr.Extent, true, (short)esriScreenCache.esriAllScreenCaches);

                            IFeatureSelection pfsel = (IFeatureSelection)cls_globals.GetFeatureLayer(cls_globals.CURRENT_POLE_LAYER);

                            pfsel.Add(ftr);

                            //At this point I have the feature created and selected.

                            editor.SelectionAnchor.MoveTo((IPoint)ftr.Shape, editor.Display);

                            editor.SelectionAnchor.Draw(editor.Display);                                                                      

                            editor.StopOperation("Create Pole at Current GPS Location");

                            //This is where I want it added to the editor.EditSelection so the user can immediately 

                            //start editing the attributes in the editor attribute window.

                            cls_globals.CURRENT_MXDOC.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

It looks like you doing most things correctly. The EditSelection property just picks up editable features in the current selection so there's nothing to do there.

Duncan is kind of on the right track, to get the attributes window to recognize the new selection you'll have to fire a selection changed event. I usually do this on the map through selection events.

Hope this helps.

      //update selection

      ISelectionEvents pSelEvents;

      pSelEvents = ArcMap.Document.FocusMap as ISelectionEvents;

      pSelEvents.SelectionChanged();

View solution in original post

0 Kudos
3 Replies
DuncanHornby
MVP Notable Contributor

According to the help the IEditor.EditSelection property is a read only property...

I think what you want to do is create an event listener. Have a look at the IEditEvents.OnSelectionChanged event?

by Anonymous User
Not applicable

It looks like you doing most things correctly. The EditSelection property just picks up editable features in the current selection so there's nothing to do there.

Duncan is kind of on the right track, to get the attributes window to recognize the new selection you'll have to fire a selection changed event. I usually do this on the map through selection events.

Hope this helps.

      //update selection

      ISelectionEvents pSelEvents;

      pSelEvents = ArcMap.Document.FocusMap as ISelectionEvents;

      pSelEvents.SelectionChanged();

0 Kudos
KennethRenner
New Contributor

Perfect!

Thank you

0 Kudos