I have a toolbar with two buttons that allow users to display an edit attribute window of a selected feature. I would like the buttons to be disabled until the user selects one feature.

Current, I somewhat have this feature working. The button is enable whened opening the document and then it is disabled after the first time opening the window (I have it in the OnUpdate Event). How can I change this so that the button is disabled when the user opens the MXD and then is enable when only one feature is selected?

I think my problem is just that i have it in the OnUpdate event?? Using Visual Basic 2008 Express, ArcGIS 10

Protected Overrides Sub OnUpdate()

Dim pFeatLyr As IFeatureLayer
pFeatLyr = GetLayerByTOC("AJ_RecommendedImprovementsLines")

'Enable Button
If GetFeatSelCount(pFeatLyr) = 1 Then
    Me.Enabled = True
    Me.Enabled = False
End If
End Sub

2 Answers 2


If this is an Add-in, you'll have to make a modification to the config.esriaddinx file also. Take a look at the section about Delay Loading in the add-in concepts help, where it says to set the onDemand attribute to false.

The line will look something like this:

<Button id="YourAddIn_Button1" class="Button1" message="Add-in command generated by Visual Studio project wizard." caption="My Button" tip="Add-in command tooltip." category="Add-In Controls" image="Images\Button1.png"  onDemand="false"/>

Maybe you add an event lister for "SelectionChanged", then toggle a public bool on the button class to enable it? Like this in C#:

IActiveViewEvents_Event activeViewEvent = ArcMap.Document.FocusMap as         
activeViewEvent.SelectionChanged += new IActiveViewEvents_SelectionChangedEventHandler(onMapSelectionChanged);

private void onMapSelectionChanged()
    btnMyButton btn = (btnMyButton)ESRI.ArcGIS.Desktop.AddIns.AddIn.FromID<btnMyButton>(ThisAddIn.IDs.btnMyButton);
    btn.IsEnabled = true;

//////Button Class
class btnMyButton : ESRI.ArcGIS.Desktop.AddIns.Button
    public bool isEnabled;

protected override void OnUpdate()

    Enabled = isEnabled;

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.