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'm attempting to write the number of items matching a given query to the statusbar. when i debug through the code, i am able to step through and see the message hit the statusbar, but then it immediately disappears. Below is the function in question.

public class CollisionViewExtension : Extension
{
     private static IQueryable<Collision> AllCollisions
    {
        get { return _allCollisions ?? (_allCollisions = Database.Query<Collision>(Collision.Query).ToList().AsQueryable()); }
    }
    ...
    public static void DrawCollisionPoints(string whereClause)
    {
        var matches = new List<Collision>();
        try
        {
            matches = AllCollisions.Where(string.IsNullOrWhiteSpace(whereClause) ? "1=1" : whereClause, null).ToList();

            if (CurrentSpatialQueryShape != null)
            {
                matches = matches.Where(x => IsPointInPolygon(CurrentSpatialQueryShape, (IPoint)x.Point)).ToList();
            }
        }
        catch (Exception)
        {
            System.Windows.Forms.MessageBox.Show("Invalid query");
        }

        FeatureInserter.InsertFeatures(matches);

        var layer = new FeatureLayerLocator(ArcMap.Document.FocusMap).GetFeatureLayerByModelName("CollisionView-Collisions");
        if (layer == null)
        {
            ArcMap.Document.FocusMap.AddLayer(FeatureLayer);
        }

        ArcMap.Application.Caption = string.Format("{0} collisions", matches.Count);
        Application.DoEvents();
        ArcMap.Application.StatusBar.set_Message((int)esriStatusBarPanes.esriStatusMain, string.Format("{0} collisions", matches.Count));

        ArcMap.Document.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, FeatureLayer, null);
        ArcMap.Application.StatusBar.set_Message((int)esriStatusBarPanes.esriStatusMain, string.Format("{0} collisions", matches.Count));

        CurrentQuery = whereClause;
    }
    ...
}

I feel like this is pretty much how I've seen it used in all the examples, but for some reason my message is not displayed. Asked another, probably simpler way, is there any way to show the user a count of the features in a particular layer in the statusbar?

share|improve this question
    
The DoEvents and PartialRefresh are what are probably overwriting it. Try setting the message after DoEvents, and setting it again after the PartialRefresh. –  blah238 Mar 24 '13 at 4:06
    
@blah238, I've updated the code based on your suggestion. i also, for kicks, set the application caption to see if that worked. there was no difference in the statusbar, but the application caption was set properly. –  nathan gonzalez Mar 24 '13 at 4:41
    
Maybe stick another DoEvents before the last statusbar message. Dunno. Is there any more code executing after what we see here? –  blah238 Mar 24 '13 at 5:34
    
no other code. that function is generally called after everything else is resolved. tried adding an Application.DoEvents() in a couple places, none made a difference. thinking about giving up on this one. –  nathan gonzalez Mar 24 '13 at 20:46
add comment

1 Answer 1

The code you are showing us, is placed inside an extension, what means that it will always be called from another place. This other place is better suited to write to the statusbar, so your extension could instead return the message to the calling place.

If for example your extension is called from an arcmap-tool, then you can overwrite the tool's OnRefresh() method to set the statusbar. Other events would otherwise blank out the statusbar.

share|improve this answer
add comment

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.