Since this only took a couple of minutes to write I will post an example. However, if you need someone to write solutions for you then we have many people who work in Professional Services that can build applications for you.
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace EngineWindowsApplication1
{
public partial class Form1 : Form
{
private enum LayerType { Districts, SubDistricts };
IList<IGeometry> m_districts = null;
IList<IGeometry> m_subDistricts = null;
IFeatureLayer m_districtsLayer = null;
IFeatureLayer m_subDistrictsLayer = null;
string m_districtsKeyFieldName = "STATE_NAME";
string m_subDistrictsKeyFieldName = "NAME";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//could be used to cache the geoms, may not be appropriate for large feature classes
m_districts = new List<IGeometry>();
m_subDistricts = new List<IGeometry>();
m_districtsLayer = (IFeatureLayer)axMapControl1.get_Layer(1);
m_subDistrictsLayer = (IFeatureLayer)axMapControl1.get_Layer(0);
//get the districts layer
IFeatureCursor fCur = m_districtsLayer.FeatureClass.Search(null,false);
populateCBO(fCur, m_districtsKeyFieldName, false, LayerType.Districts, comboBox1);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
reset();
IGeometry g = getGeomAndZoom(LayerType.Districts, comboBox1.SelectedIndex, comboBox1.SelectedItem.ToString());
ISpatialFilter sf = new SpatialFilter() { Geometry = g, SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects };
IFeatureCursor fCur = m_subDistrictsLayer.FeatureClass.Search(sf, false);
comboBox2.Enabled = true;
populateCBO(fCur, m_subDistrictsKeyFieldName, true, LayerType.SubDistricts, comboBox2);
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
IGeometry g = getGeomAndZoom(LayerType.SubDistricts, comboBox2.SelectedIndex, comboBox2.SelectedItem.ToString());
}
private IGeometry getGeomAndZoom(LayerType lt, int i, string val)
{
string fieldName = "";
IGeometry g = null;
IFeatureLayer fl = null;
IList<IGeometry> l = null;
switch (lt)
{
case LayerType.Districts:
fieldName = m_districtsKeyFieldName;
fl = m_districtsLayer;
l = m_districts;
break;
case LayerType.SubDistricts:
fieldName = m_subDistrictsKeyFieldName;
fl = m_subDistrictsLayer;
l = m_subDistricts;
break;
default:
break;
}
if (l.Count > 0)
g = l;
else
{
IQueryFilter qf = new QueryFilter() { WhereClause = fieldName + " = '" + val + "'"};
g = fl.FeatureClass.Search(qf, false).NextFeature().Shape;
}
axMapControl1.Extent = g.Envelope;
axMapControl1.Refresh();
return g;
}
private void populateCBO(IFeatureCursor fCur, string fieldName, bool cacheGeoms, LayerType lt, ComboBox cbo)
{
IFeature f = fCur.NextFeature();
while (f != null)
{
cbo.Items.Add(f.get_Value(f.Fields.FindField(fieldName)));
if (cacheGeoms)
{
switch (lt)
{
case LayerType.Districts:
m_districts.Add(f.Shape);
break;
case LayerType.SubDistricts:
m_subDistricts.Add(f.Shape);
break;
default:
break;
}
}
f = fCur.NextFeature();
}
}
private void reset()
{
m_subDistricts = new List<IGeometry>();
comboBox2.Text = "";
comboBox2.Items.Clear();
comboBox2.Enabled = false;
}
}
}