Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;


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.

share|improve this question
up vote 3 down vote accepted

IUniqueValueRenderer.Field Property

share|improve this answer
That webpage also links to sample code. – James Schek Feb 15 '11 at 22:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.