# GeoCollection.Remove(string) API does not seem to work

**URL:** <https://community.thinkgeo.com/t/geocollection-remove-string-api-does-not-seem-to-work/3501>\
**Category:** WPF\
**Created:** [September 6, 2013, 12:38pm UTC](https://community.thinkgeo.com/t/geocollection-remove-string-api-does-not-seem-to-work/3501 "2013-09-06T12:38:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [September 6, 2013, 12:38pm UTC](https://community.thinkgeo.com/t/geocollection-remove-string-api-does-not-seem-to-work/3501/1 "2013-09-06T12:38:05Z")

</div>

Guys,  
  
  
  
Looks&nbsp;like&nbsp;the&nbsp;GeoCollection.Remove(string)&nbsp;API&nbsp;does&nbsp;not&nbsp;work.&nbsp;&nbsp;&nbsp;I&nbsp;modified&nbsp;your&nbsp;sample&nbsp;AddSimpleMarkers&nbsp;class&nbsp;to&nbsp;be&nbsp;able&nbsp;to&nbsp;remove&nbsp;a&nbsp;marker&nbsp;as&nbsp;follows:

> `using`&nbsp;`System;`  
> `using`&nbsp;`System.Linq;`  
> `using`&nbsp;`System.Windows;`  
> `using`&nbsp;`System.Windows.Controls;`  
> `using`&nbsp;`System.Windows.Media.Imaging;`  
> `using`&nbsp;`ThinkGeo.MapSuite.Core;`  
> `using`&nbsp;`ThinkGeo.MapSuite.WpfDesktopEdition;`  
> &nbsp;  
> `namespace`&nbsp;`CSHowDoISamples`  
> `{`  
> `    ``public`&nbsp;`partial`&nbsp;`class`&nbsp;`AddSimpleMarkers : UserControl`  
> `    ``{`  
> `        ``public`&nbsp;`AddSimpleMarkers()`  
> `        ``{`  
> `            ``InitializeComponent();`  
> `        ``}`  
> &nbsp;  
> `        ``private`&nbsp;`void`&nbsp;`WpfMap_Loaded(``object`&nbsp;`sender, RoutedEventArgs e)`  
> `        ``{`  
> `            ``wpfMap1.MapUnit = GeographyUnit.DecimalDegree;`  
> `            ``wpfMap1.CurrentExtent = ``new`&nbsp;`RectangleShape(-155.733, 95.60, 104.42, -81.9);`  
> &nbsp;  
> `            ``WorldMapKitWmsWpfOverlay worldMapKitOverlay = ``new`&nbsp;`WorldMapKitWmsWpfOverlay();`  
> `            ``wpfMap1.Overlays.Add(worldMapKitOverlay);`  
> &nbsp;  
> `            ``SimpleMarkerOverlay markerOverlay = ``new`&nbsp;`SimpleMarkerOverlay();`  
> `            ``wpfMap1.Overlays.Add(``"MarkerOverlay"``, markerOverlay);`  
> &nbsp;  
> `            ``wpfMap1.Refresh();`  
> `        ``}`  
> &nbsp;  
> `        ``private`&nbsp;`void`&nbsp;`wpfMap1_MapClick(``object`&nbsp;`sender, MapClickWpfMapEventArgs e)`  
> `        ``{`  
> `            ``if`&nbsp;`(e.MouseButton != MapMouseButton.Left) ``return``;`  
> &nbsp;  
> `            ``SimpleMarkerOverlay markerOverlay = (SimpleMarkerOverlay)wpfMap1.Overlays[``"MarkerOverlay"``];`  
> `            ``Marker marker = ``new`&nbsp;`Marker(e.WorldLocation);`  
> `            ``marker.ImageSource = ``new`&nbsp;`BitmapImage(``new`&nbsp;`Uri(``"/Resources/AQUA.png"``, UriKind.RelativeOrAbsolute));`  
> `            ``marker.Width = 20;`  
> `            ``marker.Height = 34;`  
> `            ``marker.YOffset = -17;`  
> &nbsp;  
> &nbsp;  
> `            ``var contextMenu = ``new`&nbsp;`ContextMenu();`  
> `            ``var menuItem = ``new`&nbsp;`MenuItem();`  
> `            ``menuItem.Header = ``"Remove"``;`  
> `            ``menuItem.Name = ``"Marker"`&nbsp;`+ marker.GetHashCode().ToString();`  
> `            ``menuItem.Click += OnRemoveMarkerRequested;`  
> `            ``contextMenu.Items.Add(menuItem);`  
> `            ``marker.ContextMenu = contextMenu;`  
> &nbsp;  
> `            ``marker.Name = menuItem.Name;`  
> `            ``markerOverlay.Markers.Add(marker);`  
> `            ``markerOverlay.Refresh();`  
> `        ``}`  
> &nbsp;  
> `        ``private`&nbsp;`void`&nbsp;`OnRemoveMarkerRequested(``object`&nbsp;`sender, RoutedEventArgs e)`  
> `        ``{`  
> `            ``var markerOverlay = (SimpleMarkerOverlay)wpfMap1.Overlays[``"MarkerOverlay"``];`  
> `            ``var markerName = ((MenuItem) e.Source).Name;`  
> `           ``// does not work?`  
> `            ``markerOverlay.Markers.Remove(markerName);`  
> `            ``var marker = markerOverlay.Markers.First(m => ``string``.Compare(m.Name, markerName, StringComparison.OrdinalIgnoreCase) == 0);`  
> `            ``markerOverlay.Markers.Remove(marker);`  
> &nbsp;  
> `            ``// remember to unhook MenuItem from OnRemoveMarkerRequested`  
> `            ``markerOverlay.Refresh();`  
> `        ``}`  
> `    ``}`  
> `}`

  
  
  
If&nbsp;you&nbsp;run&nbsp;the&nbsp;sample,&nbsp;an&nbsp;exception&nbsp;is&nbsp;not&nbsp;thrown&nbsp;by&nbsp;the&nbsp;LINQ&nbsp;statement&nbsp;indicating&nbsp;that&nbsp;the&nbsp;marker&nbsp;was&nbsp;not&nbsp;removed.&nbsp;&nbsp;However,&nbsp;grabbing&nbsp;the&nbsp;marker&nbsp;instance&nbsp;and&nbsp;remove&nbsp;it&nbsp;works&nbsp;correctly.&nbsp;&nbsp;Any&nbsp;ideas&nbsp;or&nbsp;a&nbsp;better&nbsp;recommendation&nbsp;on&nbsp;how&nbsp;to&nbsp;remove&nbsp;markers?  
  
  
  
TIA.  
  
  
  
  
  
  
  
  
  
  
W

---

<div class="post-metadata">

**Author:** ![Klaus3](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/e5b9ba/32.png) [@Klaus3](https://community.thinkgeo.com/u/Klaus3)\
**Post date:** [September 6, 2013, 1:21pm UTC](https://community.thinkgeo.com/t/geocollection-remove-string-api-does-not-seem-to-work/3501/2 "2013-09-06T13:21:06Z")

</div>

Never&nbsp;mind,&nbsp;figured&nbsp;it&nbsp;out.&nbsp;&nbsp;Needed&nbsp;to&nbsp;add&nbsp;markers&nbsp;to&nbsp;GeoCollection\<T\>&nbsp;using&nbsp;the&nbsp;Add(string,&nbsp;T&nbsp;item)&nbsp;API&nbsp;instead&nbsp;of&nbsp;the&nbsp;Add(T)&nbsp;API.

---

<div class="post-metadata">

**Author:** ![Summer1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@Summer1](https://community.thinkgeo.com/u/Summer1)\
**Post date:** [September 8, 2013, 9:22pm UTC](https://community.thinkgeo.com/t/geocollection-remove-string-api-does-not-seem-to-work/3501/3 "2013-09-08T21:22:42Z")

</div>

Hi&nbsp;Klaus,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Glad&nbsp;to&nbsp;hear&nbsp;the&nbsp;problem&nbsp;is&nbsp;sorted&nbsp;out,&nbsp;if&nbsp;you&nbsp;have&nbsp;any&nbsp;other&nbsp;question,&nbsp;please&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;us&nbsp;know.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Summer.&nbsp;
