How to update the attribute window after programatically select a feature?

548
4
Jump to solution
07-04-2012 08:03 AM
Highlighted
Occasional Contributor II
Hi Everybody:

    I am writing code to programatically create new features, select features on the map, and keep the attribute window open to display the new feature in an edit session. However, even though I could select the feature and get it highlighted on the map, the attribute window does not display the new selected feature properly. Following is the code I used to select the feature:

// This section of code is repeatly run to clear previously created feature and select newly created feature                        // select the new feature     (mapLayer as IFeatureSelection).Clear();     (mapLayer as IFeatureSelection).SelectionSet.Add(newFeature.OID);      // open the attribute window     UID attributeWinId = new UIDClass();     attributeWinId.Value = "esriEditor.AttributeWindow";     IAttributeWindow attributeWin = m_editor.FindExtension(attributeWinId) as IAttributeWindow;     attributeWin.Visible = true;                          // refresh the view     (m_Application.Document as IMxDocument).ActiveView.Refresh();


For the first time this section of code is executed in an ArcMap edit session, the attribute window is opened (originally closed) and it displays the newly selected feature, but for the second time this code runs the displayed feature in attribute window wouldn't be updated automatically. How to synchonize it with the actual selection? Thank you!
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Occasional Contributor
The following link might be useful.
http://forums.esri.com/Thread.asp?c=93&f=1707&t=224203&g=1

Hi thaviti:

    I tried with the firing the event, but the Attribute Window still doesn't update. Do I need to implement event handler for "SelectionChanged"?
    Thank you!

View solution in original post

Reply
0 Kudos
4 Replies
Highlighted
Occasional Contributor
Fire SelectionChanged after changing the selectionset.

Hi Everybody:

    I am writing code to programatically create new features, select features on the map, and keep the attribute window open to display the new feature in an edit session. However, even though I could select the feature and get it highlighted on the map, the attribute window does not display the new selected feature properly. Following is the code I used to select the feature:


// This section of code is repeatly run to clear previously created feature and select newly created feature
                
    // select the new feature
    (mapLayer as IFeatureSelection).Clear();
    (mapLayer as IFeatureSelection).SelectionSet.Add(newFeature.OID);

(mapLayer as IFeatureSelection).SelectionChanged();

    // open the attribute window
    UID attributeWinId = new UIDClass();
    attributeWinId.Value = "esriEditor.AttributeWindow";
    IAttributeWindow attributeWin = m_editor.FindExtension(attributeWinId) as IAttributeWindow;
    attributeWin.Visible = true;
                   
    // refresh the view
    (m_Application.Document as IMxDocument).ActiveView.Refresh();


For the first time this section of code is executed in an ArcMap edit session, the attribute window is opened (originally closed) and it displays the newly selected feature, but for the second time this code runs the displayed feature in attribute window wouldn't be updated automatically. How to synchonize it with the actual selection? Thank you!
Reply
0 Kudos
Highlighted
Occasional Contributor II
Hi thaviti:

    I tried with the firing the event, but the Attribute Window still doesn't update. Do I need to implement event handler for "SelectionChanged"?
    Thank you!

Fire SelectionChanged after changing the selectionset.
Reply
0 Kudos
Highlighted
Occasional Contributor
The following link might be useful.
http://forums.esri.com/Thread.asp?c=93&f=1707&t=224203&g=1

Hi thaviti:

    I tried with the firing the event, but the Attribute Window still doesn't update. Do I need to implement event handler for "SelectionChanged"?
    Thank you!

View solution in original post

Reply
0 Kudos
Highlighted
Occasional Contributor II
Hi thaviti:

    Thank you! The link answers my question. For convenience of the future reader, I copy-paste the follow from the link:

=========================================================================================
Re: iFeatureSelection.SelectionChanged doesn't work 
Author Michael Knight 
Date Jun 05, 2007 
Message IFeatureSelection.SelectionChanged updates the layer so it will update the display when you refresh. Why it doesn't fire the ActiveView Selection Changed Event I don't know. But if you are writing custom code to select features you must notify the display that the selection has changed. Try using ISelectionEvents. It will fire the ActiveView Selection Changed Event:

'vb
Dim pSelectionEvents As ISelectionEvents
Set pSelectionEvents = pMap 'valid IMap refernce
pSelectionEvents.SelectionChanged 
  Michael Knight
GIS Solutions Architect
Contract Land Staff, LLC
Stafford, Texas

http://www.contractlandstaff.com
================================================================================================
Reply
0 Kudos