Can't get IIdentifyDialog2 to work in VB.net

174
3
06-21-2020 07:18 AM
MatthiasKl
New Contributor

I want to use the ArcMap Identify-Tool inside a WindowsForm. So I've created a button and added a clickevent:

    Private Sub btnIdentify_Click(sender As Object, e As EventArgs) Handles btnIdentify.Click 
        Dim intObjectID As Integer = lstResults.SelectedValue
        Dim pLayer As ILayer2 = pDocument.FocusMap.Layer(0)
        DoIdentify(pLayer, intObjectID)
    End Sub ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I've also created a sub procdedure similar to the one in the ArcObjects API Reference for .NET

    Private Sub DoIdentify(ByVal pLayer As ILayer, ByVal intObjectID As Integer) 
        If pActiveView Is Nothing Or pLayer Is Nothing Or intObjectID <= 0 Then
            Return
        End If
 
        Dim pMap As IMap = pActiveView.FocusMap
        Dim pIdentifyDialog As IIdentifyDialog = New IdentifyDialogClass()
        pIdentifyDialog.Map = pMap
 
        pIdentifyDialog.ClearLayers()
        Dim pScreenDisplay As IScreenDisplay = pActiveView.ScreenDisplay
 
        Dim pDisplay As IDisplay = pScreenDisplay
        pIdentifyDialog.Display = pDisplay
 
        pIdentifyDialog.AddLayerIdentifyOID(pLayer, intObjectID)
        pIdentifyDialog.Show()
    End Sub ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

This code works perfectly fine. But I really want to use the new IIdentifyDialog2 Interface. But if I change the code to

    Private Sub DoIdentify(ByVal pLayer As ILayer, ByVal intObjectID As Integer) 
        If pActiveView Is Nothing Or pLayer Is Nothing Or intObjectID <= 0 Then
            Return
        End If
 
        Dim pMap As IBasicMap2 = pActiveView.FocusMap
        Dim pIdentifyDialog As IIdentifyDialog2 = New IdentifyDialogClass()
        pIdentifyDialog.BasicMap = pMap
 
        pIdentifyDialog.ClearLayers()
        Dim pScreenDisplay As IScreenDisplay3 = pActiveView.ScreenDisplay
 
        Dim pDisplay As IDisplay = pScreenDisplay
        pIdentifyDialog.Display = pDisplay
 
        pIdentifyDialog.AddLayerIdentifyOID(pLayer, intObjectID)
        pIdentifyDialog.Show()
    End Sub ‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 
I get a NullReferenceException at pIdentifyDialog.ClearLayers() I already tried so many things but somehow I can't get it to work with the new Identify-Tool. Does anyone know the answer?

Tags (2)
Reply
0 Kudos
3 Replies
GintautasKmieliauskas
Regular Contributor

Hi Matthias,

IIdentifyDialog2 works with tables, when IIdentifyDialog works with layers.

https://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#CartoUI_library.htm 

Reply
0 Kudos
MatthiasKl
New Contributor

Okay, so I only have to use AddTableIdentifyOID instead of AddLayerIdentifyOID and pass a ITable instead of a ILayer? Do I still need ClearLayers? I'm sorry but I am somehow lost. Could you give me a hint what I exactly need to change in my code?

Reply
0 Kudos
GintautasKmieliauskas
Regular Contributor

I have found one sample, you can follow it and check if it works:

https://forum.esri-cis.ru/index.php?qa=36329&qa_1=identify

Site in Russian language, but code in VB

At first work with IIdentifyDialog variable (until ClearLayers).

After cast it to IIdentifyDialog2 variable and try your workflow

Reply
0 Kudos