IUniqueValueRenderer problems

743
3
04-12-2011 11:42 AM
Sergiydodon
New Contributor II
I have some problems with code:

public override void OnClick()
{
            IMxDocument pMxDoc = (IMxDocument)m_application.Document;
            IMap pMap = pMxDoc.FocusMap;
            ILayer player = pMap.get_Layer(0);
            IUniqueValueRenderer pUVR = new UniqueValueRendererClass();
            pUVR = ((IGeoFeatureLayer)player).Renderer as IUniqueValueRenderer;
            for (int i = 0; i < pUVR.ValueCount; i++)
            {
                if (pUVR.get_Value(i) != "?????????????")
                    pUVR.AddReferenceValue(pUVR.get_Value(i), "?????????????");
            }
            IRendererPropertyPage pRPpage = new UniqueValuePropertyPageClass();
            ((IGeoFeatureLayer)player).RendererPropertyPageClassID = pRPpage.ClassID;
            pMxDoc.ActivatedView.Refresh();
            pMxDoc.CurrentContentsView.Refresh(null);
            pMxDoc.UpdateContents();
        }
this code group all unique value by AddReferenceValue method and it shows everything correctly in activeview, but not in TOC. It's still shows in TOC all my unique value and any kind of refresh and update methods doesn't help me.
Even in a layer properties - symbology correct representation. Help me please to correct TOC representation.
0 Kudos
3 Replies
JamesCrandall
MVP Frequent Contributor
First, I am more comfortable with VB.NET, so if I mention something that is irrelevent because it is something else in C# then forgive me.  But there are a couple of things that sort of jump out at me and might be worth looking into.

1. I don't see you including any SimpleMarkerSymbol or other symbol as a parameter in the .AddValue method of your renderer.  The parameters I've always set for a uniqueval renderer are as such:

pUVRenderer.AddValue(pfeature.Value(pFClass.FindField("FlagType")), "", pSym)


Where pSym is an ISimpleMarkerSymbol (or some other type) with its color, style, size, etc.. set up already.

2. This doesn't see right or in the wrong location (however, this may simply be a C# thing that I am not understanding):

pUVR = ((IGeoFeatureLayer)player).Renderer as IUniqueValueRenderer;


Shouldn't the IGeoFeatureLayer.Rendere property be set at the very last step?  That is, arent' you supposed to loop thru the FeatureCursor and set all of the pUVRenderer.AddValue properties first, then finally set the GeoFeatureLayer's .Renderer?

3.  After an UpdateContents, try a partialRefresh on the ActiveView:

            pDoc.UpdateContents()
            pDoc.ActiveView.Refresh()
            pDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, Nothing, Nothing)
0 Kudos
Sergiydodon
New Contributor II
First of all thanks, James for your answer.
I don't see you including any SimpleMarkerSymbol or other symbol as a parameter in the .AddValue method
of your renderer. The parameters I've always set for a uniqueval renderer are as such:

In my Mxd project, I don't want to use AddValue at all. I'm just want to take existing layer from Mxd, which already have all necessary value with acceptable symbology and group them in one group.
it's got to be something like this:

1 - Dim pLayer As ILayer
     Set pLayer = pMap.Layer(1) - I take existing layer in Mxd project? which already have  16 values for UniqueValueRenderer (valuecount = 16)
2 - in a loop i group all my values in a one group
as an example:(AddReferenceValue)
pUniqueValueRenderer.AddReferenceValue "Highway", "Freeway"
3 - refresh everything
that is how i see situation.
0 Kudos
Sergiydodon
New Contributor II
At last I found what i did wrong. If I use addreferenceValue method, I have to remove this items from values.
public override void OnClick()
{
IMxDocument pMxDoc = (IMxDocument)m_application.Document;
IMap pMap = pMxDoc.FocusMap;
ILayer player = pMap.get_Layer(0);
IUniqueValueRenderer pUVR = new UniqueValueRendererClass();
pUVR = ((IGeoFeatureLayer)player).Renderer as IUniqueValueRenderer;
for (int i = 0; i < pUVR.ValueCount; i++)
{
if (pUVR.get_Value(i) != "Ð?зеÑ?жинÑ�кий")
string s = ppFRenderer.get_Value(ii);
ppFRenderer.RemoveValue(ppFRenderer.get_Value(ii));
pUVR.AddReferenceValue(s, "Ð?зеÑ?жинÑ�кий");
}
IRendererPropertyPage pRPpage = new UniqueValuePropertyPageClass();
((IGeoFeatureLayer)player).RendererPropertyPageClassID = pRPpage.ClassID;
pMxDoc.ActivatedView.Refresh();
pMxDoc.CurrentContentsView.Refresh(null);
pMxDoc.UpdateContents();
}
0 Kudos