Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
Else
    Me.Enabled = False
End If
End Sub
share|improve this question

2 Answers 2

up vote 2 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

 
discard

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.