# Layer Order Vs Standard controls order

**URL:** <https://community.thinkgeo.com/t/layer-order-vs-standard-controls-order/216>\
**Category:** WinForms\
**Created:** [February 6, 2009, 9:30am UTC](https://community.thinkgeo.com/t/layer-order-vs-standard-controls-order/216 "2009-02-06T09:30:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nelson](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nelson](https://community.thinkgeo.com/u/Nelson)\
**Post date:** [February 6, 2009, 9:30am UTC](https://community.thinkgeo.com/t/layer-order-vs-standard-controls-order/216/1 "2009-02-06T09:30:44Z")

</div>

I&nbsp;have&nbsp;a&nbsp;curious&nbsp;question.&nbsp;I&nbsp;have&nbsp;noticed&nbsp;that&nbsp;the&nbsp;first&nbsp;layer&nbsp;added&nbsp;will&nbsp;be&nbsp;the&nbsp;bottom-most&nbsp;layer&nbsp;in&nbsp;a&nbsp;map&nbsp;which&nbsp;does&nbsp;make&nbsp;sense.&nbsp;My&nbsp;question&nbsp;relates&nbsp;to&nbsp;how&nbsp;other&nbsp;controls&nbsp;and&nbsp;objects&nbsp;interact&nbsp;with&nbsp;this&nbsp;order.&nbsp;For&nbsp;instance,&nbsp;a&nbsp;tree&nbsp;view's&nbsp;first&nbsp;object&nbsp;is&nbsp;displayed&nbsp;top&nbsp;most.&nbsp;If&nbsp;I&nbsp;want&nbsp;to&nbsp;maintain&nbsp;my&nbsp;layers&nbsp;in&nbsp;a&nbsp;tree&nbsp;view&nbsp;and&nbsp;dynamically&nbsp;add&nbsp;layers&nbsp;to&nbsp;the&nbsp;map,&nbsp;they&nbsp;will&nbsp;be&nbsp;in&nbsp;opposite&nbsp;order.

I&nbsp;would&nbsp;like&nbsp;to&nbsp;always&nbsp;have&nbsp;the&nbsp;top&nbsp;most&nbsp;layer&nbsp;in&nbsp;the&nbsp;map&nbsp;be&nbsp;the&nbsp;top&nbsp;most&nbsp;object&nbsp;in&nbsp;the&nbsp;tree&nbsp;view&nbsp;so&nbsp;that&nbsp;it&nbsp;is&nbsp;intuitive&nbsp;to&nbsp;the&nbsp;user.&nbsp;I'm&nbsp;pretty&nbsp;sure&nbsp;this&nbsp;is&nbsp;something&nbsp;that&nbsp;many&nbsp;people&nbsp;have&nbsp;run&nbsp;into&nbsp;so&nbsp;I&nbsp;am&nbsp;interested&nbsp;in&nbsp;what&nbsp;some&nbsp;user's&nbsp;solutions&nbsp;have&nbsp;been.

While&nbsp;this&nbsp;particular&nbsp;circumstance&nbsp;relates&nbsp;to&nbsp;my&nbsp;Desktop&nbsp;Application,&nbsp;with&nbsp;the&nbsp;Web&nbsp;Application&nbsp;I&nbsp;got&nbsp;around&nbsp;this&nbsp;by&nbsp;binding&nbsp;a&nbsp;Checkbox&nbsp;list&nbsp;to&nbsp;a&nbsp;SQL&nbsp;statement&nbsp;and&nbsp;reversed&nbsp;the&nbsp;order&nbsp;depending&nbsp;on&nbsp;whether&nbsp;I&nbsp;was&nbsp;adding&nbsp;the&nbsp;layers&nbsp;to&nbsp;the&nbsp;map&nbsp;control&nbsp;or&nbsp;binding&nbsp;to&nbsp;the&nbsp;Checkbox&nbsp;list.&nbsp;This&nbsp;was&nbsp;kind&nbsp;of&nbsp;hacky&nbsp;and&nbsp;I&nbsp;thought&nbsp;others&nbsp;might&nbsp;have&nbsp;a&nbsp;better&nbsp;approach.

Thanks.&nbsp;

---

<div class="post-metadata">

**Author:** ![brendan](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/50afbb/32.png) [@brendan](https://community.thinkgeo.com/u/brendan)\
**Post date:** [February 7, 2009, 5:45am UTC](https://community.thinkgeo.com/t/layer-order-vs-standard-controls-order/216/2 "2009-02-07T05:45:44Z")

</div>

Hi&nbsp;Nelson.&nbsp;I&nbsp;haven't&nbsp;had&nbsp;to&nbsp;do&nbsp;this,&nbsp;and&nbsp;others&nbsp;would&nbsp;probably&nbsp;have&nbsp;a&nbsp;much&nbsp;neater&nbsp;solution,&nbsp;but&nbsp;perhaps&nbsp;I&nbsp;can&nbsp;add&nbsp;some&nbsp;value:P&nbsp;  
  
  
  
When&nbsp;you&nbsp;add&nbsp;your&nbsp;layers&nbsp;to&nbsp;the&nbsp;map&nbsp;control,&nbsp;perhaps&nbsp;keep&nbsp;a&nbsp;reference&nbsp;to&nbsp;them&nbsp;in&nbsp;a&nbsp;&nbsp;&nbsp;` List< KeyValuePair< int, InMemoryFeatureLayer> >  `&nbsp;or&nbsp;similar.

That&nbsp;way&nbsp;you&nbsp;can&nbsp;set&nbsp;the&nbsp;key&nbsp;of&nbsp;the&nbsp;KeyValuePair&nbsp;as&nbsp;a&nbsp;rank&nbsp;to&nbsp;keep&nbsp;track&nbsp;of&nbsp;the&nbsp;order&nbsp;that&nbsp;you&nbsp;add&nbsp;your&nbsp;layers.&nbsp;You&nbsp;can&nbsp;also&nbsp;use&nbsp;a&nbsp;simple&nbsp;Linq&nbsp;Statement&nbsp;to&nbsp;reverse&nbsp;this&nbsp;order&nbsp;when&nbsp;binding&nbsp;to&nbsp;the&nbsp;checkboxlist&nbsp;"list.OrderByDescending(entity&nbsp;=\>&nbsp;entity.Key)".&nbsp;  
  
  
  
I'm&nbsp;not&nbsp;sure&nbsp;that&nbsp;you&nbsp;will&nbsp;find&nbsp;a&nbsp;built&nbsp;in&nbsp;method,&nbsp;but&nbsp;a&nbsp;simple&nbsp;list&nbsp;with&nbsp;a&nbsp;reference&nbsp;to&nbsp;the&nbsp;layers&nbsp;you&nbsp;add&nbsp;may&nbsp;help.&nbsp;  
  
  
  
Regards&nbsp;  
  
Brendan

---

<div class="post-metadata">

**Author:** ![Ben](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ben/32/25720_2.png) [@Ben](https://community.thinkgeo.com/u/Ben)\
**Post date:** [February 9, 2009, 1:23am UTC](https://community.thinkgeo.com/t/layer-order-vs-standard-controls-order/216/3 "2009-02-09T01:23:55Z")

</div>

Nelson,&nbsp;  
  
  
  
Also&nbsp;you&nbsp;can&nbsp;add&nbsp;your&nbsp;own&nbsp;Extension&nbsp;Method&nbsp;to&nbsp;the&nbsp;LayerOverlay,&nbsp;which&nbsp;will&nbsp;make&nbsp;it&nbsp;very&nbsp;easy&nbsp;to&nbsp;use.&nbsp;  
  
  
  
Creating&nbsp;the&nbsp;following&nbsp;class&nbsp;  
  
`   public static class LayerOverLayExtension    {        public static Layer GetLayerReversed(this LayerOverlay layerOverlay, int index)        {            // usually you need to do the parameter checking for "index", here just ignore it to make it simple            return layerOverlay.Layers[layerOverlay.Layers.Count - index - 1];        }`  
Then&nbsp;you&nbsp;can&nbsp;call&nbsp;the&nbsp;method&nbsp;directly.&nbsp;  
  
`winformsMap1.StaticOverlay.GetLayerReversed(0);`  
Thanks,&nbsp;  
  
  
  
Ben&nbsp;  
  
&nbsp;

---

<div class="post-metadata">

**Author:** ![brendan](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/b/50afbb/32.png) [@brendan](https://community.thinkgeo.com/u/brendan)\
**Post date:** [February 9, 2009, 7:40am UTC](https://community.thinkgeo.com/t/layer-order-vs-standard-controls-order/216/4 "2009-02-09T07:40:34Z")

</div>

I&nbsp;think&nbsp;that’s&nbsp;a&nbsp;more&nbsp;elegant&nbsp;solution:P

---

<div class="post-metadata">

**Author:** ![Nelson](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/n/dec6dc/32.png) [@Nelson](https://community.thinkgeo.com/u/Nelson)\
**Post date:** [February 9, 2009, 8:23am UTC](https://community.thinkgeo.com/t/layer-order-vs-standard-controls-order/216/5 "2009-02-09T08:23:46Z")

</div>

Thank&nbsp;you&nbsp;both.&nbsp;Very&nbsp;neat!

---

<div class="post-metadata">

**Author:** ![Ben](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/ben/32/25720_2.png) [@Ben](https://community.thinkgeo.com/u/Ben)\
**Post date:** [February 9, 2009, 7:57pm UTC](https://community.thinkgeo.com/t/layer-order-vs-standard-controls-order/216/6 "2009-02-09T19:57:45Z")

</div>

It's&nbsp;my&nbsp;pleasure:)
