How to find if a feature is included on the edited workspace through code?

09-24-2011 09:43 PM
Occasional Contributor II

Is there an effecient way to find the workspace that is being edited so that we can specify if a feature is included on the edit session or not?

My story is that I need to know if any feature (randomly selected from the map) in the map can be edited or no since every feature in the map can be edited through code although it is out side the  edited workspace, and also there are featurelayers of different types e.g. CAD Layers, ShapeFiles, FeatureClass (SDE & PGDB), & etc...

Thanks for any try to help....
0 Kudos
4 Replies
New Contributor III
Acquire IEditor interface
Use IEditor.EditWorkspace.DatasetNames to find if it contains your Dataset.


IFeatureClass.IFeatureDataSet.Workspace cast to IWorkspaceEdit - use try/catch and use
0 Kudos
Occasional Contributor II
Thank you dubravko for your reply..

I just used your hints as follows:

        Dim pmap As IMap
            pmap = g_pMxDoc.FocusMap
            Dim penumlayer As IEnumLayer
            penumlayer = pmap.Layers
            Dim player As ILayer
            player = penumlayer.Next
            Dim pfeatlayer As IFeatureLayer
            Dim pfeatcls As IFeatureClass
            Dim pwrkspcedit As IWorkspaceEdit
            Dim pdataset As IFeatureDataset
            Dim plist As String
            Do Until player Is Nothing
                If (TypeOf player Is IFeatureLayer) Then
                    pfeatlayer = player
                    pfeatcls = pfeatlayer.FeatureClass
                    pdataset = pfeatcls.FeatureDataset
                    pwrkspcedit = pdataset.Workspace
                    If pwrkspcedit.IsBeingEdited Then
                        plist = pfeatlayer.Name & vbNewLine & plist
                    End If
                End If
                player = penumlayer.Next

But when running the above code an error is occured: "Object variable is not set to an object" at the bold line up. Please advise,

Also a sample code on how to check if the layer belongs to the edited workspace is preferable.
0 Kudos
New Contributor III
cast IFeatureClass in IDataset

IDataset pDataset = pFeatureLayer.FeatureClass as IDataset;
IWorkspace pWorksopace = pDataset.Workspace;
IWorkspaceEdit pWorkspaceEdit = pWorksopace as IWorkspaceEdit;
bool isInEditSession = pWorkspaceEdit.IsBeingEdited();
0 Kudos
Occasional Contributor II
Thank you v.much my friend dubravko.antonic for your perfect solution...

I just convert your sample into Visual Basic syntax and everything went great..

You`ve got my respect.....
0 Kudos