AnsweredAssumed Answered

Problem with manipulating simple renderer for shapefiles

Question asked by Adjutant on Mar 26, 2012
Latest reply on Mar 27, 2012 by Adjutant
Greetings,

I'm having trouble trying to change the symbol properties of a simple renderer, used to display shapefiles.

The following code works perfectly (the shape data is displayed in some random default colour - e.g. light lime):
        IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();         IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(shapeFileFolder, 0);         IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(shapeFileBasename);         shapeFileLayer = new FeatureLayerClass();         shapeFileLayer.FeatureClass = featureClass;         shapeFileLayer.Name = shapeFileBasename;         shapeFileLayer.Visible = true;          mapControl.ActiveView.FocusMap.AddLayer(shapeFileLayer);         shapeFileLayers[shapeFileLayer.Name] = (FeatureLayerClass)shapeFileLayer;


However, when I add code in order to change the associated symbol colour (and line symbol) of the shapefile data, then the symbol fill colour simply defaults to black and the line symbol remains unchanged.
        IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();         IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(shapeFileFolder, 0);         IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(shapeFileBasename);         shapeFileLayer = new FeatureLayerClass();         shapeFileLayer.FeatureClass = featureClass;         shapeFileLayer.Name = shapeFileBasename;         shapeFileLayer.Visible = true;      IGeoFeatureLayer geoLayer = shapeFileLayer as IGeoFeatureLayer;  ISimpleRenderer renderer = geoLayer.Renderer as ISimpleRenderer;  if (renderer != null)  {  ILineSymbol lineSymbol = new SimpleLineSymbolClass();  lineSymbol.Width = 1;  lineSymbol.Color.RGB = 0x777777;    IFillSymbol fillSymbol = new SimpleFillSymbolClass();  fillSymbol.Color = new RgbColorClass();  fillSymbol.Color.RGB = 0x00FF00;  fillSymbol.Outline = lineSymbol;    renderer.Symbol = (ISymbol)fillSymbol;  }            mapControl.ActiveView.FocusMap.AddLayer(shapeFileLayer);         shapeFileLayers[shapeFileLayer.Name] = (FeatureLayerClass)shapeFileLayer;


This thread : http://forums.arcgis.com/threads/2251-Set-Symbology....?highlight=shapefile+layer+featureclass , seems to be handling a similar issue but used a unique value renderer and simply updated symbol colour properties in the same way...
I've also tried created a new renderer and assigning it to the layer, but that also didn't help.

What am I doing wrong?

Outcomes