Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

IUniqueValueRenderer.Field Property http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//001200000rs0000000

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

Your Answer

 
discard

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.