I currently have a layer file - in this case one of the United States. This layer contains a shape for each state so if I were to open the TOC Control and expand the "United States" I would see Alabama, Alaska, etc etc.
Currently, if I wanted to I could change the color of all the states through the following code:
IRgbColor rgb = new RgbColorClass();
ColorDialog myColorDlg = new ColorDialog(); ///This is the windows color picker
DialogResult res = myColorDlg.ShowDialog();
if(res == DialogResult.OK)
{
IFeatureLayer featureLayer = layer as IFeatureLayer;
IFeatureClass featureClass = featureLayer.FeatureClass;
rgb.Red = myColorDlg.Red;
rgb.Blue = myColorDlg.Blue;
rgb.Green = myColorDlg.Green;
IGeoFeatureLayer geoFeatureLayer = layer as IGeoFeatureLayer;
ILineSymbol lineSymbol = new SimpleLineSymbolClass();
lineSymbol.Width = 1.0;
lineSymbol.Color = (IColor)rgb;
ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
fillSymbol.Outline = lineSymbol;
fillSymbol.Color = (IColor)rgb;
ISimpleRenderer simpleRenderer = new SimpleRendererClass();
simpleRenderer.Symbol = (ISymbol)fillSymbol;
geoFeatureRenderer.Renderer = (IFeatureRenderer)simpleRenderer;
myAxMapControl.Refresh();
}
The question now is, how can I change each state separately. I'm aware that if I use the built in TOC control I should be able to do this with ILegendClass; however, I wish to use a different TOC Control.