ArcObjects Library Reference  

clscopy_table_sel

Migrating from VB6 to VB .NET for ArcGIS 10

[C#]

clscopy_table_sel.cs


[Visual Basic .NET]

clscopy_table_sel.vb

Option Strict Off
Option Explicit On
<System.Runtime.InteropServices.ProgId("clscopy_table_sel_NET.clscopy_table_sel_NET")> Public Class clscopy_table_sel
    Implements ESRI.ArcGIS.SystemUI.ICommand

    Private m_pApp As ESRI.ArcGIS.Framework.IApplication
    Private m_pMXDoc As ESRI.ArcGIS.ArcMapUI.IMxDocument
    Private m_pWorkSpace As ESRI.ArcGIS.Geodatabase.IWorkspace
    Private m_pTableView As ESRI.ArcGIS.GeoDatabaseUI.ITableView2

    Private ReadOnly Property ICommand_Bitmap() As System.Int32 Implements ESRI.ArcGIS.SystemUI.ICommand.Bitmap
        Get
        End Get
    End Property

    Private ReadOnly Property ICommand_Caption() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Caption
        Get
            ICommand_Caption = "Copy Table Selection VB2008"
        End Get
    End Property

    Private ReadOnly Property ICommand_Category() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Category
        Get
            ICommand_Category = "Developer Samples"
        End Get
    End Property

    Private ReadOnly Property ICommand_Checked() As Boolean Implements ESRI.ArcGIS.SystemUI.ICommand.Checked
        Get
        End Get
    End Property


    Private ReadOnly Property ICommand_Enabled() As Boolean Implements ESRI.ArcGIS.SystemUI.ICommand.Enabled

        Get
            ' Make it enabled if it is in a table context menu.
            ICommand_Enabled = False

            Dim pAppWindows As ESRI.ArcGIS.ArcMapUI.IApplicationWindows
            Dim pWindowSet As ESRI.ArcGIS.esriSystem.ISet = Nothing
            Dim pTableWindow As ESRI.ArcGIS.ArcMapUI.ITableWindow
            Dim pTableControl As ESRI.ArcGIS.GeoDatabaseUI.ITableControl
            Dim pSelSet As ESRI.ArcGIS.Geodatabase.ISelectionSet
            Dim pTableWindow3 As ESRI.ArcGIS.ArcMapUI.ITableWindow3

            pTableWindow3 = New ESRI.ArcGIS.ArcMapUI.TableWindow()
            pTableWindow3.FindOpenTableWindows(pWindowSet)
            pAppWindows = m_pApp
            pWindowSet.Reset()
            pTableWindow = pWindowSet.Next

            Do Until pTableWindow Is Nothing
                pTableControl = pTableWindow.TableControl
                m_pTableView = pTableControl
                pSelSet = m_pTableView.SelectionSet
                If pSelSet.Count > 0 Then
                    ICommand_Enabled = True
                End If
                pTableWindow = pWindowSet.Next
            Loop
        End Get
    End Property

    Private ReadOnly Property ICommand_HelpContextID() As Integer Implements ESRI.ArcGIS.SystemUI.ICommand.HelpContextID
        Get
        End Get
    End Property

    Private ReadOnly Property ICommand_HelpFile() As String Implements ESRI.ArcGIS.SystemUI.ICommand.HelpFile
        Get
            Return ""
        End Get
    End Property

    Private ReadOnly Property ICommand_Message() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Message
        Get
            ICommand_Message = "Copies the selected records in the table window VB2008"
        End Get
    End Property

    Private ReadOnly Property ICommand_Name() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Name
        Get
            ICommand_Name = "Developer Samples_Copy Table Selection VB2008"
        End Get
    End Property

    Private ReadOnly Property ICommand_Tooltip() As String Implements ESRI.ArcGIS.SystemUI.ICommand.Tooltip
        Get
            ICommand_Tooltip = "Validate Table Selection VB2008"
        End Get
    End Property

    Private Sub ICommand_OnClick() Implements ESRI.ArcGIS.SystemUI.ICommand.OnClick
        copy()
    End Sub

    Private Sub ICommand_OnCreate(ByVal hook As Object) Implements ESRI.ArcGIS.SystemUI.ICommand.OnCreate
        m_pApp = hook
        m_pMXDoc = m_pApp.Document
    End Sub

    '################### Private Routines

    Private Sub copy()
        ' Get the selection from the table.
        Dim pInSelSet As ESRI.ArcGIS.Geodatabase.ISelectionSet
        Dim pTable As ESRI.ArcGIS.Geodatabase.ITable
        pInSelSet = m_pTableView.SelectionSet
        pTable = m_pTableView.Table

        Dim pCur As ESRI.ArcGIS.Geodatabase.ICursor = Nothing
        Dim pRow As ESRI.ArcGIS.Geodatabase.IRowBuffer
        Dim pFlds As ESRI.ArcGIS.Geodatabase.IFields
        'Dim pFld As ESRI.ArcGIS.Geodatabase.IField.
        Dim iCnt As Short
        Dim iind As Short
        pInSelSet.Search(Nothing, False, pCur)
        pRow = pCur.NextRow
        Dim strR As String = ""
        pFlds = pRow.Fields
        iCnt = pFlds.FieldCount
        Do Until pRow Is Nothing
            For iind = 0 To iCnt - 1
                If Not TypeOf pRow.Value(iind) Is ESRI.ArcGIS.Geometry.IGeometry Then
                    'UPGRADE_WARNING: Couldn't resolve default property of object pRow.Value(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
                    strR = strR & pRow.Value(iind) & ","
                End If
            Next iind
            strR = Left(strR, Len(strR) - 1) ' Remove the trailing comma.
            strR = strR & vbNewLine
            pRow = pCur.NextRow
        Loop

        My.Computer.Clipboard.Clear()
        My.Computer.Clipboard.SetText(strR)
    End Sub

End Class