1

I created a GIS using ArcObjects, my application needs to be connected with a geodatabase stored in SQL Server. I used ARCSDE to connect my application to the database and when the database is connected, my application loads two tables - the first one is called Commune and the second one is called Parcelle. Their esriDatasetType is: esriDatasetType.esriDTFeatureClass.

A Parcelle belongs to only one Commune; and a Commmune can contain many Parcelles.

What I want to do is start the session and edit the Parcelle layer without the possibility to edit the Commune layer. When I use my code, I can edit both layers in the map:

public static void Start(IEngineEditor _engineEditor, IMapControl4 map, string targetLayerName)
{
    //If an edit session has already been started, exit.
    if (_engineEditor.EditState == esriEngineEditState.esriEngineStateEditing) return;

    //Start editing the workspace of the first feature layer found.
    for (int layerCounter = 0; layerCounter <= map.LayerCount - 1; layerCounter++)
    {
        ILayer currentLayer = map.get_Layer(layerCounter);
        if (currentLayer.Name != targetLayerName) continue;
        try
        {
            if (currentLayer is IFeatureLayer)
            {
                IFeatureLayer featureLayer = currentLayer as IFeatureLayer;
                IDataset dataset = featureLayer.FeatureClass as IDataset;
                IWorkspace workspace = dataset.Workspace;
                _engineEditor.StartEditing(workspace, map.ActiveView.FocusMap);

                ((IEngineEditLayers)_engineEditor).SetTargetLayer(featureLayer, 0);
                break;
            }
        }
        catch (Exception ex)
        {
            Dialog.info("Info", ex.Message);
        }
    }
}

My function has 3 parameters: IEngineEditor, IMapControl4 and the name of the layer that I want to edit, which is the layer Parcelle in my case.

1

Well i found a solution, i've just set the IFeatureLayer.Selectable = false for the ILayer Commune and it's working great.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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