Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question
up vote 3 down vote accepted

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"/>
share|improve this answer

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;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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