QueryFeaturesButton.vb
' Copyright 2011 ESRI ' ' All rights reserved under the copyright laws of the United States ' and applicable international laws, treaties, and conventions. ' ' You may freely redistribute and use this sample code, with or ' without modification, provided you include the original copyright ' notice and use restrictions. ' ' See the use restrictions. ' Imports Microsoft.VisualBasic Imports System Imports System.Collections.Generic Imports System.ComponentModel Imports System.Data Imports System.Drawing Imports System.Linq Imports System.Text Imports ESRI.ArcGISExplorer Imports ESRI.ArcGISExplorer.Application Imports ESRI.ArcGISExplorer.Mapping Imports ESRI.ArcGISExplorer.Geometry Imports ESRI.ArcGISExplorer.Data Imports ESRI.ArcGISExplorer.Threading ''' <summary> ''' Implements a custom query features button ''' </summary> ''' <remarks> ''' Allows the user to digitize a polygon on the map, then uses ''' the resulting geometry to query the selected feature layer ''' and display the results in a DataGridView on a form. ''' The grid is populated by binding the query results using ''' a TableBindingAdapter. ''' </remarks> Public Class QueryFeaturesButton Inherits ESRI.ArcGISExplorer.Application.Button ''' <summary> ''' Raised when the button is clicked on the ribbon ''' </summary> Public Overrides Sub OnClick() ' get the first selected item in the map. It's safe to assume the item is a ' feature layer because the declaration of this button in the AddIns.xml specifies ' the E3_FeatureLayerSelectedCondition condition Dim layer As FeatureLayer = TryCast(ESRI.ArcGISExplorer.Application.Application.SelectedItems(0), FeatureLayer) ' allow the user to digitize a polygon on the map Dim polygon As Polygon = ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.TrackPolygon() Try ' query the feature layer for the features that intersect the polygon Dim rowCollection As RowCollection = layer.Table.Search(New Filter(polygon, FilterSearchOptions.Intersects)) ' create the table binding adapter and fill it Dim tableBindingAdapter As TableBindingAdapter = New TableBindingAdapter(rowCollection) tableBindingAdapter.UseColumnAliasNames = True tableBindingAdapter.UseCodedValueDomains = True tableBindingAdapter.Fill() ' display the results Dim resultsForm As QueryResultsForm = New QueryResultsForm(tableBindingAdapter) resultsForm.ShowDialog() Catch ex As NullReferenceException System.Windows.Forms.MessageBox.Show("No features were selected. Please try again.") End Try End Sub End Class