PDA

View Full Version : C# ActiveX - Can't find user-drawn polygon shapes in Shapes collection?



citrix_99301
06-20-2012, 06:00 PM
I am attempting to highlight all the pushpins in all the datasets after a user draws a polygon shape on the MapPoint ActiveX object in a Windows Form (.NET Framework 4.0)

oMap.Shapes.Count = 1 (according to my watch window), however oMap.Shapes[0] shows oMap.Shapes[0] throws an exception System.OutOfMemoryException' MapPoint.Shape {System.OutOfMemoryException}

Am I missing something here?

Thanks in advance for your time,

Andre Ranieri




MapPoint.Shape objShape;
MapPoint.Map oMap = this.axMapPoint.ActiveMap;
foreach (MapPoint.DataSet oDS in oMap.DataSets)
{
if (oMap.Shapes.Count >= 1)
{

MapPoint.Recordset oRS = oDS.QueryShape(oMap.Shapes[0]); Code Fails here

oRS.MoveFirst();
if (oRS.EOF)
{
continue;
}

oRS.MoveFirst();
if (oRS.EOF)
{
continue;
}

while (!oRS.EOF)
{
oRS.Pushpin.Highlight = true;
}
}
}

Winwaed
06-21-2012, 08:09 AM
Yes it fails because you can't index COM arrays like this in C#. If you want to work your way through the lot, then I would use foreach - like you are doing for the datasets.

If you want to work with a specific index, you have to do it like this (note:1-referenced, NOT 0-referenced):


object oidx = (object)1;
MapPoint.Shape oShp = oShapes.get_Item(ref oidx);

Also be sure to check that oShp is valid for the QueryShape() method - it cannot be used with text boxes and 2-point lines.

citrix_99301
06-21-2012, 10:17 AM
Thanks - I haven't developed in MapPoint in 3-4 years and had forgotten this.

My shapes should all be polygons, squares and circles. Do I need some kind of validation to make sure that nothing else is selected?

If the user creates several polygons, is there some mechanism by which I can iterate through the Shapes collection and determine which one is the selected one?

Thanks,

Andre

Winwaed
06-22-2012, 07:47 AM
You need to look at the shape's ShapeType and AutoShapeType properties: Shape object (http://msdn.microsoft.com/en-us/library/aa493077)