QueryTask Events are not accessible in Silverlight API

747
4
04-19-2010 08:04 PM
SourishChakraborty
New Contributor
Hi,
I am using Silverlight API and VS2008 with SP1.I am unable to access QueryTAsk Events like ExecuteCompleted,Failed and PropertChanged from VB.NET code.It's possible to access these events from C#.NET code.

Can anybody tell me ,if I am skipping something.Is there anyway to access those public events from VB.NET code.

Is I am missing some fundamental things of .NET concept.
Please guide.
Thanks & Regrads
0 Kudos
4 Replies
HubertLo
New Contributor
I have no problem accessing it when I tested it in a sample project of mine. I am sure you can do this in VB.NET if you change the syntax from C#. Here are the snippets of the code from my sample project:

Calling the QueryTask

ESRI.ArcGIS.Client.Tasks.QueryTask queryTask =
    new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/Map...");
queryTask.ExecuteCompleted += queryTask_ExecuteCompleted;
ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
query.Geometry = MyMap.Extent;// geoRectangle;
query.OutSpatialReferenceWKID = MyMap.SpatialReference.WKID;
query.ReturnGeometry = true;
query.SpatialRelationship = SpatialRelationship.esriSpatialRelIntersects;
query.OutFields.AddRange(new string[] { "FID", "CITY_NAME", "STATE_NAME", "POP1990 " });
queryTask.ExecuteAsync(query);


The ExecuteCompleted event handler

void queryTask_ExecuteCompleted(object sender, QueryEventArgs args)
{
    ESRI.ArcGIS.Client.Tasks.FeatureSet featureSet = args.FeatureSet;

    if (featureSet == null || featureSet.Features.Count < 1)
    {
        MessageBox.Show("No features retured from query");
        return;
    }

    GraphicsLayer graphicsLayer = MyMap.Layers["SQL2008Spatial"] as GraphicsLayer;

    foreach (Graphic graphic in featureSet.Features)
    {
        if (graphic.Geometry.Extent.YMax == graphic.Geometry.Extent.YMin)
        {
            graphic.Symbol = DefaultPointMarkerSymbol;
        }
        else
        {
            graphic.Symbol = DefaultLineSymbol;
        }
        graphicsLayer.Graphics.Add(graphic);
    }

}
0 Kudos
SourishChakraborty
New Contributor
Hi,
I have used the C# code,it's working fine but while using the VB.NET code intellisense is not showing the Public events like "ExecuteCompleted" etc.

See the snapshot of the intellisense attached.

Thanks & Regrads
0 Kudos
LanceCrumbliss
Occasional Contributor II
i think you'll need to use the AddHandler statement in order to access the events, ie

Dim queryTask as New QueryTask(url)
AddHandler queryTask.ExecuteCompleted, AddressOf queryTask _ExecuteCompleted


and then write the event handler "queryTask_ExecuteCompleted"

 Private Sub queryTask_ExecuteCompleted(ByVal sender As Object, ByVal args As QueryEventArgs)
             'Do amazing things
 End Sub


lance
0 Kudos
SourishChakraborty
New Contributor
Yup!11...Done...
Thanks & Regards
0 Kudos