Find correct layer in map

2481
16
12-02-2010 12:02 PM
HenkZwols
Occasional Contributor
Hello,

In a combobox i store all the names of layers that are in the TOC:
water
buildings
buildings
...
As you can see there are 2 layers with the same name, but different definition queries: buildings.
When user selects a layer in the combobox i perform an action on that layer. My routine 'selectLayerByName' fails when user selects the second building layer.

What code do i need to find the correct layer?
[Edit] Or what extra information do i need to store in de combobox to find the correct layer?

Gr. Henk
0 Kudos
16 Replies
LeoDonahue
Occasional Contributor III
I supposed changing the name of the building layers to something that indicates the type of def query would be out of the question?

The only other way, is to find your layer by ID, and not change the order of the layers in the mxd.
0 Kudos
HenkZwols
Occasional Contributor
I was afraid for this answer and it happened. Renaming seems the only solution.
Thanks.
0 Kudos
Venkata_RaoTammineni
Occasional Contributor
Once layer is renamed...there will be issue right ?Even we should not call it as an issue tooo....
0 Kudos
LeoDonahue
Occasional Contributor III
I was afraid for this answer and it happened. Renaming seems the only solution.
Thanks.

Well, even if "you" can tell which layer is the right layer, how do the "users" know which layer they are choosing if both layers have the same name in the combo box?
0 Kudos
AlexanderGray
Occasional Contributor III
I have dealt with a similar situation in .net (both vb and C#.)  The way I dealt with it was to build a list of IFeatureLayers (generic list (of IFeatureLayer).   Then bind the list to combobox and set the display property to "Name".  This way your combobox doesn't contain a list of featurelayer name strings but a list of actual featurelayer objects.  When the user picks one the selecteditem is a feature layer not a string but the featurelayer so there is no need to find the layer by name.  Of course showing the user two items in a combo box with the same name is not very nice for the user.  But there are other solutions to that (showing the group and name, etc.)
0 Kudos
HenkZwols
Occasional Contributor
Well, even if "you" can tell which layer is the right layer, how do the "users" know which layer they are choosing if both layers have the same name in the combo box?


Good point!
0 Kudos
HenkZwols
Occasional Contributor
I have dealt with a similar situation in .net (both vb and C#.)  The way I dealt with it was to build a list of IFeatureLayers (generic list (of IFeatureLayer).   Then bind the list to combobox and set the display property to "Name".  This way your combobox doesn't contain a list of featurelayer name strings but a list of actual featurelayer objects.  When the user picks one the selecteditem is a feature layer not a string but the featurelayer so there is no need to find the layer by name.  Of course showing the user two items in a combo box with the same name is not very nice for the user.  But there are other solutions to that (showing the group and name, etc.)


Thank for this tip!
I agree that showing two items with the same name is not nice.
Do you have other ideas for names without using groupnames? Something like "Buildings (1ste entry)", Buildings (2de entry) ?
0 Kudos
HenkZwols
Occasional Contributor
And what about selecting (hilite) the layer in the TOC that matches with the item user selects in the combobox?
0 Kudos
Venkata_RaoTammineni
Occasional Contributor
Thank for this tip!
I agree that showing two items with the same name is not nice.
Do you have other ideas for names without using groupnames? Something like "Buildings (1ste entry)", Buildings (2de entry) ?


Why don't you make names as by type Commercial building and residential or by size Large Constructions and Small Constructions  something like that ?
0 Kudos