5 Replies Latest reply on Sep 20, 2011 4:47 AM by tgisarc

    Editing table attributes of a layer file .NET

      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
        • Re: Editing table attributes of a layer file .NET
          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.
          • Re: Editing table attributes of a layer file .NET
            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


                    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


                    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)
                            MsgBox("Started Transaction")

                                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"
                                    feature = updatecursor.NextFeature()
                                MsgBox("Looped all transactions")
                            Catch comEx As COMException
                            End Try

                        End If


                    End While
                End Sub
            • Re: Editing table attributes of a layer file .NET
              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)
              • Re: Editing table attributes of a layer file .NET
                TOP NOTCH - Thank you so much
                • Re: Editing table attributes of a layer file .NET
                  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.