Hi,
I also had come across the situation and below is the solution I found. This displays a unique reference in combobox for a layer in the map. Hence if there is a layer with duplicate name in map then combobox will have duplicate names but each refers to unique layer in map.
Create a custom class for Feature Layer and return layer name on �??ToStrong()�?? method. Add the custom feature layer object to combox as shown below.
FeatureLayerDropDownItem FLayerDropDownObj = new FeatureLayerDropDownItem((IFeatureLayer)layer);
cmbBox.Items.Add(FLayerDropDownObj);
Below is the code for creating custom class.
///<summary>
/// Custom Class the refers to a Feature Layer. This object has overridden method 'ToString' methods that returns FeatureLayer's Name.
/// This cutom object is used to load the Layers into the Combobox control
///</summary>
public class FeatureLayerDropDownItem
{
///<summary>
/// Feature Layer that this object refer to
///</summary>
IFeatureLayer m_FeatureLayer;
///<summary>
/// Constructor
///</summary>
///<param name="featureLayer">Feature Layer that this object refers to</param>
public FeatureLayerDropDownItem(IFeatureLayer featureLayer)
{
m_FeatureLayer = featureLayer;
}
///<summary>
/// Name of the Feature Layer
///</summary>
///<returns></returns>
public override string ToString()
{
if (m_FeatureLayer == null) return "";
//return the name of the feature layer as the ToString value that will be displayed in the drop down list
return m_FeatureLayer.Name;
}
///<summary>
/// Checks the equality of the current and passed object.
/// The equality condition is true if their associtaed FeatureLayer objects are same and false otheriwse.
///</summary>
///<param name="obj">Object to check the equality</param>
///<returns>The equality condition is true if their associtaed FeatureLayer objects are same and false otheriwse.</returns>
public override bool Equals(object obj)
{
try
{
//if both are null, then return true
if (m_FeatureLayer == null && obj == null) return true;
//return false, if any one is null
else if (m_FeatureLayer == null || obj == null) return false;
//checks if the passed object type is same as that of this object
if (!(obj is FeatureLayerDropDownItem)) return false;
//checks whether FeatureLayer of both the objects are equal. If yes, then declare that both the objects are equal.
if (((FeatureLayerDropDownItem)obj).FeatureLayerAssociated == m_FeatureLayer) return true;
else return false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
///<summary>
/// Feature Layer that this object refer to
///</summary>
public IFeatureLayer FeatureLayerAssociated
{
get
{
return m_FeatureLayer;
}
set
{
m_FeatureLayer = value;
}
}
///<summary>
/// Geometry Type of the Features that this Feature Layer stores
///</summary>
public esriGeometryType LayerGeometryType
{
get
{
//return esriGeometryNull if the Associtaed FeatureLayer or its associated FeatureClass is null.
if (m_FeatureLayer == null || m_FeatureLayer.FeatureClass == null) return esriGeometryType.esriGeometryNull;
else return m_FeatureLayer.FeatureClass.ShapeType;
}
}
}