MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Selecting a Shape by Name in C#

This is a discussion on Selecting a Shape by Name in C# within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; According to the documentation, I should be able to find a shape by its name using the Shapes collection's Item ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  5 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 04-11-2007
Winwaed's Avatar
Mapping-Tools.com
Red Belt
 
Join Date: Feb 2004
Posts: 785
Blog Entries: 4
Selecting a Shape by Name in C#

According to the documentation, I should be able to find a shape by its name using the Shapes collection's Item method.
I've done this in the past with VB6, but it crashes with C#.

Has anyone managed to find a shape without iterating through the entire collection? (I see in another thread, Wilfried iterates through the collection looking for a matching name).

Eg. something like:

MapPoint.Shape myShape = myMap.Shapes.Item("fred");

Perhaps I'm seeing a variant / string problem?

Richard
__________________
Winwaed Software Technology LLC
http://www.winwaed.com
See http://www.mapping-tools.com for MapPoint Tools
Pre-Order MapPoint 2009 today: http://www.mapping-tools.com/mappoint2009
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 04-13-2007
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,055
Re: Selecting a Shape by Name in C#

Hi Richard,

Almost, but it is get_Item and it has to be a ref to the name like this:

Code:
object o = theNameToFind;
Shape s = MP.ActiveMap.Shapes.get_Item(ref o);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 04-13-2007
Winwaed's Avatar
Mapping-Tools.com
Red Belt
 
Join Date: Feb 2004
Posts: 785
Blog Entries: 4
Re: Selecting a Shape by Name in C#

Wilfried,

That's what I had originally - but it started to throw an exception!

Is a normal C# string okay, or does it have to be cast as something else? (I'm thinking of the dozen or so different string types found on Windows C++!)

Richard
__________________
Winwaed Software Technology LLC
http://www.winwaed.com
See http://www.mapping-tools.com for MapPoint Tools
Pre-Order MapPoint 2009 today: http://www.mapping-tools.com/mappoint2009
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 04-13-2007
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,055
Re: Selecting a Shape by Name in C#

Hi Richard,

Normal string. I just tryed this in a test project and it works. I paste it here:

Code:
Shape s = MP.ActiveMap.Shapes.AddShape(GeoAutoShapeType.geoShapeRadius, loc, dia, dia);
s.Name = "wilfried";
object o = s.Name;
s = MP.ActiveMap.Shapes.get_Item(ref o);
Console.WriteLine(s.Name);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 04-15-2007
Winwaed's Avatar
Mapping-Tools.com
Red Belt
 
Join Date: Feb 2004
Posts: 785
Blog Entries: 4
Re: Selecting a Shape by Name in C#

Hmmm....
I'll have another look at my code tomorrow.

Thanks Wilfried - although the above code doesn't rule out the possibility that the text is a "non-conventional" string - you copy from the name property into the object that you use as the parameter.

Richard
__________________
Winwaed Software Technology LLC
http://www.winwaed.com
See http://www.mapping-tools.com for MapPoint Tools
Pre-Order MapPoint 2009 today: http://www.mapping-tools.com/mappoint2009
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 04-17-2007
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,055
Re: Selecting a Shape by Name in C#

Hi Richard,

This is true. It is a conventional string, but there can be a big difference between this:

Code:
string name = "wilfried";
object o = name;
s = MP.ActiveMap.Shapes.get_Item(ref o);
and this:

Code:
object o = "wilfried";
s = MP.ActiveMap.Shapes.get_Item(ref o);
Because it is given by reference. So in the first case there is possible a copy of "wilfried" in memory where the address is hold by name. But in second case the pointer points to read only memory. So maybe that is the reason ? If of course the first one gives no exception and the second gives one.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/selecting-shape-name-c-5825.html

Posted By For Type Date
Lat/Long in MapPoint 2002 - MapPoint Articles - MP2K Magazine This thread Refback 04-27-2007 04:43 AM
Microsoft MapPoint 2006 - MP2K Magazine This thread Refback 04-17-2007 01:59 PM
MapPoint Gets New General Manager - MapPoint News - MP2K Magazine This thread Refback 04-14-2007 08:54 AM
Determing Whether A Point Is Located Inside Polygon - MapPoint Articles - MP2K Magazine This thread Refback 04-11-2007 10:26 PM
Programming MapPoint in .NET - MP2K Magazine This thread Refback 04-11-2007 10:10 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Does an object reside in my Shape or Shape boundaries? hotrdd MapPoint 2006/2009 Discussion 1 08-04-2005 09:51 PM
Selecting cities in drivetime Anonymous MapPoint 2006/2009 Discussion 5 02-02-2005 04:21 PM
Selecting Shape Based on Name Anonymous MapPoint 2006/2009 Discussion 1 09-07-2004 10:01 AM
Selecting a prviously drawn shape CSG MapPoint 2006/2009 Discussion 1 03-24-2004 10:08 AM
Selecting pushpins within a shape Anonymous MapPoint 2006/2009 Discussion 1 09-26-2002 08:11 AM


All times are GMT -5. The time now is 11:45 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map

Flight Times
At Holiday Hypermarket not only can you book some great value flights but we have links to help you check flight times for arrivals and departures from each airport.

Flights to Turkey
Find and book flights to Turkey. Travel Counsellors can help with travel to Turkey including flights and accommodation.

Holidays to Thailand
The best cultures and backgrounds make Thailand an interesting and memorable country to visit. Book great value holidays to Thailand online at dealchecker.co.uk.

Barbados Holidays
Barbados holidays can be a wonderful break from the rat race or an exciting, action packed adventure. Plan the perfect holiday in Barbados.

Holidays
For bargain holidays to destinations including Mexico, South Africa, India and more, visit ULookUBook online today. Check out our free travel guides to help you make an informed decision for your holidays.

Price Comparison
Price comparison is the name of the game at Travel.co.uk. Visit our website and see for yourself.

Holidays to Goa
Golden beaches, coconut trees. Visit On The Beach for holidays to Goa, and experience India!


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51