Fire SelectionChanged event

923
4
04-17-2011 10:34 PM
ChaesoonLim
New Contributor II
Hi, All

I am using VB.NET of ArcEngine 9.3.

Question is how I can fire OnSelectionChanged event when selecting feature.

My code is like below.

----------------------------------------
       Dim featLayer As IFeatureLayer
       featLayer = CreateLayerAndAddtoMap(pFC)

        If featLayer Is Nothing Then Exit Sub

        Dim featSel As IFeatureSelection = CType(featLayer, IFeatureSelection)

        Dim qFilter As IQueryFilter = New QueryFilter
        qFilter.WhereClause = pFilterStr

        Dim activeView As IActiveView = axmapcontrol.ActiveView
        activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection,Nothing,activeView.Extent)

        featSel.Clear()
        featSel.SelectFeatures(qFilter, esriSelectionResultEnum.esriSelectionResultNew, True)
        featSel.SelectionChanged()

        activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection,Nothing,activeView.Extent)
-----------------------------------
This code select feature well, but doesn't fire AxMapControl1.OnSelectionChanged event.
In debuging mode, after calling "featSel.SelectionChanged()", this doesn't go into the event sub routine.
I want to enable "Clear Selected Features Button" after selecting feature.
How can I fire SelectionChanged event?

Thanks in advance.
0 Kudos
4 Replies
JohnHauck
Occasional Contributor II
I'll have to look at this some more but ISelectionEvents::SelectionChanged will fire the event properly. You could cast your IMap to ISelectionEvents and call SelectionChanged.
0 Kudos
ChaesoonLim
New Contributor II
Thanks, John.

I coded as you suggested. But unfortunately the result is same as before.
I attached my very simple code.
Would you test my code and check it.

The code is VB.NET 2008.
Test procedure is like this.

1. edit the line qFilter.WhereClause = "OBJECTID = 254" in Sub
btnSelectQuery_Click
2. start debugging.
3. click Add Data button and add your feature class.
4. start editing
5. click "SelectQuery" button that I added.
6. open attribute window

Can you see the attribute of the selected feature in the attribure window?
I couldn't see. And the featSel.SelectionChanged() code doesn't fire ISelectionEvents.SelectionChanged event.

Why? it's very strange. Is my code something wrong?
Please check the code and give me some suggestion.

Thanks a lot.
0 Kudos
JohnHauck
Occasional Contributor II
I made the following changes:

    'Private WithEvents m_pSelectionEvents As Map
    Private m_pSelectionEvents As ISelectionEvents



In Form_Load:

        ' m_pSelectionEvents = DirectCast(m_mapControl.Map, Map)
        m_pSelectionEvents = CType(m_mapControl.Map, ISelectionEvents)


In btnSelectQuery_Click:

        'featSel.SelectionChanged()
        m_pSelectionEvents.SelectionChanged()
0 Kudos
ChaesoonLim
New Contributor II
Hi, John.

Thanks for your rapid reply.
For your kind help, everything is cleared.
I'm very happy~~

Thanks again.
0 Kudos