Editing table attributes of a layer file .NET

721
5
06-03-2011 08:15 AM
AlexandraFairbarns
New Contributor III
Hi everyone!

I have been at this for a while, so any help would be appreciated.

I am creating an add-in using .NET Studio 2008 and contains a button and a dockable window. When the user opens arcmap all they have to do is click on the add-in toolbar button, and it adds a specifed layer file (uses dxLayer/File) and the dockable window. So far so good. The user can change values on the dockable window, to update field attributes in the layer. My question is therefore, HOW DO I GET ARCMAP TO CONNECT TO (AND EDIT) THE LAYER'S TABLE OUTISIDE OF AN EDIT SESSION?

Most of what i have looked at uses workspaces, but of course the layer has been added to a blank session with no geodatabase or mxd attached. How do i get the workspace? My layer is as IFeatureLayer and can also be as IFeatureClass. I tried getting the workspace using:

Dim dataset As ESRI.ArcGIS.Geodatabase.IDataset = CType(mylayer, ESRI.ArcGIS.Geodatabase.IDataset)

Dim working As IWorkspace = dataset.Workspace

this works until i get to opening the class, casting workspace to workspace2 to find if its in an editing session - then it crashes arcmap. happens for every function that uses workspace. What is going on?????????


Thank you in advance
0 Kudos
5 Replies
AlexanderGray
Occasional Contributor III
If you are dealing with a layer, you need to cast it to Ifeaturelayer and retrieve the featureclass.  Cast the featureclass to Idataset and get the workspace.  The workspace type returned from the Ifeaturelayer as idataset may not implement iworkspace2. 

If the featureclass is not annotation or in a topology or network, you should be able to edit it outside an edit session.
0 Kudos
AlexandraFairbarns
New Contributor III
Thank You, thats exactly what ive been doing. I think i have found what is making it crash....arc cannot find the feature class dataset - it says feature dataset = nothing. When i look on the layer information it says it has a reference to a dataset on my desktop. Is there something special i need to do to get the dataset? so far my sub looks like this:

    Private Sub cmd_Calculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_Calculate.Click

        ComboBox1.Items.Clear()

        Dim currentDocument As IMxDocument = CType(My.ArcMap.Document, IMxDocument)

        Dim currentMap As IMap = currentDocument.FocusMap

        Dim activeView As IActiveView = My.ArcMap.Document.ActiveView

        Dim collectionLayers As ESRI.ArcGIS.Carto.IEnumLayer = currentMap.Layers(Nothing, True)

        If collectionLayers Is Nothing Then Exit Sub

        collectionLayers.Reset()

        MsgBox("Check 1")
        Dim loopLayer As ESRI.ArcGIS.Carto.ILayer

        loopLayer = collectionLayers.Next()

        While loopLayer IsNot Nothing

            If loopLayer.Name = "SSIM_Geological_Ranking" Then
                MsgBox("Found Layer")
                Dim SSIMLayer As ESRI.ArcGIS.Carto.ILayer
                SSIMLayer = loopLayer

                Dim findSSIMlayerID As New SSIM_getlayerindex
                Call findSSIMlayerID.GetIndexNumberFromLayerName(activeView, "SSIM_Geological_Ranking")

                Dim SSIMlayerindex As Integer
                SSIMlayerindex = findSSIMlayerID.i

                Dim SSIMfeatureLayer As ESRI.ArcGIS.Carto.IFeatureLayer = CType(SSIMLayer, ESRI.ArcGIS.Carto.IFeatureLayer)
                Dim SSIMfeatureClass As ESRI.ArcGIS.Geodatabase.IFeatureClass = SSIMfeatureLayer.FeatureClass
                Dim SSIMdataset As ESRI.ArcGIS.Geodatabase.IDataset = CType(SSIMfeatureClass.FeatureDataset, ESRI.ArcGIS.Geodatabase.IDataset)
                Dim SSIMworkspace As ESRI.ArcGIS.Geodatabase.IWorkspace = CType(SSIMdataset.Workspace, ESRI.ArcGIS.Geodatabase.IWorkspace)
                MsgBox("Found Workspace")
                Dim transactions As ITransactions = CType(SSIMworkspace, ITransactions)
                transactions.StartTransaction()
                MsgBox("Started Transaction")

                Try
                    Dim queryFilter As IQueryFilter = New QueryFilterClass()
                    queryFilter.WhereClause = "'Basin type' = 'Rift'"
                    queryFilter.SubFields = "'SSIM Basin Ranking'"

                    Dim updatecursor As IFeatureCursor = SSIMfeatureClass.Update(queryFilter, False)
                    Dim typeFieldIndex As Integer = SSIMfeatureClass.FindField("'SSIM Basin Ranking'")
                    MsgBox("Found fields")

                    Dim feature As IFeature = updatecursor.NextFeature()
                    Do While Not feature Is Nothing
                        feature.Value(typeFieldIndex) = "6"
                        updatecursor.UpdateFeature(feature)
                        feature = updatecursor.NextFeature()
                    Loop
                    MsgBox("Looped all transactions")
                    transactions.CommitTransaction()
                Catch comEx As COMException
                    transactions.AbortTransaction()
                End Try

            End If

            ComboBox1.Items.Add(loopLayer.Name)

        End While
        MsgBox("Done")
    End Sub
0 Kudos
AlexanderGray
Occasional Contributor III
Not all featureclasses belong to a feature dataset.  It is entirely possible that it is a standalone featureclass.  In that case featuredataset property will be nothing.  However, you can get the workspace from the featureclass directly by casting the featureclass to Idataset.

Dim SSIMdataset As ESRI.ArcGIS.Geodatabase.IDataset = CType(SSIMfeatureClass, ESRI.ArcGIS.Geodatabase.IDataset)
0 Kudos
AlexandraFairbarns
New Contributor III
TOP NOTCH - Thank you so much
0 Kudos
PercyJackson
New Contributor
Hi guys,

I am new to ArcGIS and Silverlight.

I am writing an application that uses the IdentifyTask function to
identify the section the user clicked on.
This then displays a datagrid containing information relevant to
the section the user clicked, such as parcel name, the town name, the zoning of that
specific parcel.

NOW, I want to be able to edit the parcel name, is this possible? How?

I am using an IDictionary object to populate the datagrid.

Thanx
0 Kudos