ArcGIS Explorer Component Help |
IndexCollection..::.FindIndexesByColumnName Method |
IndexCollection Class Example See Also |
Gets a collection of all the Index objects for a particular Column in a Table.
Namespace:
ESRI.ArcGISExplorer.DataAssembly: ESRI.ArcGISExplorer (in ESRI.ArcGISExplorer.dll) Version: 2.0.0.1500 (2.0.0.1500)
Syntax
C# |
---|
public ReadOnlyCollection<Index> FindIndexesByColumnName( string columnName ) |
Visual Basic (Declaration) |
---|
Public Function FindIndexesByColumnName ( _ columnName As String _ ) As ReadOnlyCollection(Of Index) |
Parameters
- columnName
- Type: System..::.String
The name of the Column.
Return Value
A ReadOnlyCollection object consisting of Index objects each of which represents a physical index on a Table.Examples
The code below, which would be suitable for a dockable window add-in, presents a scenario where the user can
build an index against any column in the selected feature layer. The FindIndexesByColumnName method
is used to check to whether the chosen column name already participates in any existing indexes.
CopyC#
//Get first selected map item MapItem firstSelectedMapItem = ESRI.ArcGISExplorer.Application.Application.SelectedItems[0]; //Exit if either no selection or if selection is not a FeatureLayer if ((firstSelectedMapItem == null) || !(firstSelectedMapItem is FeatureLayer)) return; //Get selected feature layer FeatureLayer someFeatureLayer = firstSelectedMapItem as FeatureLayer; //Get the Table Table someTable = someFeatureLayer.Table; //Indexes cannot be created for ArcSDE data so check for this. object dataContainer = someTable.RootDataContainer; if (dataContainer is Geodatabase) { Geodatabase gdb = dataContainer as Geodatabase; if (gdb.Type == GeodatabaseType.ArcSDE) return; } //Get the IndexCollection for the Table IndexCollection indexes = someTable.Indexes; //Simulated code to represent a user selecting an item from a list of column names System.Windows.Forms.ListBox columnsListBox = new System.Windows.Forms.ListBox(); string columnName = columnsListBox.SelectedItem.ToString(); //Check whether the column already participates in any indexes if (indexes.FindIndexesByColumnName(columnName).Count == 0) { try { //Create the new index string indexName = string.Format("idx_ {0}",columnName); Index newIndex = new Index(indexName, columnName); //if shapefile the index name parameter will be ignored //Add it to the IndexCollection indexes.Add(newIndex); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(string.Format("It was not possible to build an index for the {0} column: {1}",columnName, ex.Message)); } }
CopyVB.NET
'Get first selected map item Dim firstSelectedMapItem As MapItem = ESRI.ArcGISExplorer.Application.Application.SelectedItems.Item(0) 'Exit if either no selection or if selection is not a FeatureLayer If firstSelectedMapItem Is Nothing Or Not TypeOf firstSelectedMapItem Is FeatureLayer Then Return End If 'Get selected feature layer Dim someFeatureLayer As FeatureLayer = DirectCast(firstSelectedMapItem, FeatureLayer) 'Get the Table Dim someTable As Table = someFeatureLayer.Table 'Indexes cannot be created for ArcSDE data so check for this. Dim dataContainer As Object = someTable.RootDataContainer If TypeOf dataContainer Is Geodatabase Then Dim gdb As Geodatabase = DirectCast(dataContainer, Geodatabase) If gdb.Type = GeodatabaseType.ArcSDE Then Return End If End If 'Get the IndexCollection for the Table Dim indexes As IndexCollection = someTable.Indexes 'Simulated code to represent a user selecting an item from a list of column names Dim columnsListBox As System.Windows.Forms.ListBox = New System.Windows.Forms.ListBox() Dim columnName As String = columnsListBox.SelectedItem.ToString() 'Check whether the column already participates in any indexes If indexes.FindIndexesByColumnName(columnName).Count = 0 Then Try 'Create the new index Dim indexName As String = String.Format("idx_ 0", columnName) Dim newIndex As Index = New Index(indexName, columnName) 'if shapefile the index name parameter will be ignored 'Add it to the IndexCollection indexes.Add(newIndex) Catch ex As Exception System.Windows.Forms.MessageBox.Show(String.Format("It was not possible to build an index for the 0 column: 1", columnName, ex.Message)) End Try End If