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.

programmatically I set the custom symbology for the layers. When i started the edit session programmatically, the create feature window did not show the respective symbology assigned to feature. pl see this screenshot.

enter image description here

See the Code:

'lay' is ifeaturelayer
Dim pLayer As ILayer = lay
Dim pRender As IUniqueValueRenderer
pRender = New UniqueValueRenderer
pRender = TryCast(lay.Renderer, IUniqueValueRenderer)

Dim templateArray As IArray = New Array
subTypeField = pRender.Field(0).ToString

For pp As Integer = 0 To pRender.ValueCount - 1
  Dim newEditTemplate As IEditTemplate = editTemplateFact.Create(pRender.Label(pRender.Value(pp)), pLayer)
  templateArray.Add(newEditTemplate)
Next

pEditor.RemoveAllTemplatesInMap(pMap)
pEditor.AddTemplates(templateArray)

Dim layerExtensions As ILayerExtensions
Dim editTemplateMgr As IEditTemplateManager = Nothing
layerExtensions = pLayer

For j As Integer = 0 To layerExtensions.ExtensionCount - 1
  Dim extension As Object = layerExtensions.Extension(j)
  If TypeOf extension Is IEditTemplateManager Then
    editTemplateMgr = extension
    Exit For
  End If
Next

If Not editTemplateMgr Is Nothing Then
  Dim pEditTemplate As IEditTemplate
  For pp As Integer = 0 To pRender.ValueCount - 1
    pEditTemplate = editTemplateMgr.EditTemplate(pp)
    pEditTemplate.SetDefaultValue(subTypeField, pRender.Label(pRender.Value(pp)).ToString, True)
  Next
End If
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

In your code, you are calling AddTemplates method before calling SetDefaultValue method. I guess this cause the strange result. If calling them at reverse, then I confirmed that it works correctly.

'pLayer' is FeatureLayer Object as IGeoFeatureLayer
'pEditor is Editor Object as IEditor3
Dim pRender As IUniqueValueRenderer = TryCast(pLayer.Renderer, IUniqueValueRenderer)

Dim templateArray As IArray = New Array
Dim subTypeField As String = pRender.Field(0)

Dim editTemplateFact As IEditTemplateFactory = New EditTemplateFactory

For pp As Integer = 0 To pRender.ValueCount - 1
    Dim newEditTemplate As IEditTemplate = editTemplateFact.Create(pRender.Label(pRender.Value(pp)), pLayer)
    newEditTemplate.SetDefaultValue(subTypeField, pRender.Label(pRender.Value(pp)), True)
    templateArray.Add(newEditTemplate)
Next

pEditor.RemoveAllTemplatesInLayer(pLayer)
pEditor.AddTemplates(templateArray)

In addition, your code uses IEditor::RemoveAllTemplatesInMap method. But it seems that you are editing inside of layer. So it's recommended to use IEditor::RemoveAllTemplatesInLayer method instead of IEditor::RemoveAllTemplatesInMap method . Hope this helps you.

share|improve this answer
    
Yes its working fine..Thanks a lot –  venkat Apr 27 '13 at 5:12
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.