ArcGIS Explorer Component Help |
Index Constructor (String, String) |
Index Class Example See Also |
Initializes a new instance of the Index class which can be used to create a new named, single-column index on disk
when it is added to the IndexCollection. This constructor only applies to file geodatabase tables and feature classes.
Namespace:
ESRI.ArcGISExplorer.DataAssembly: ESRI.ArcGISExplorer (in ESRI.ArcGISExplorer.dll) Version: 2.0.0.1500 (2.0.0.1500)
Syntax
C# |
---|
public Index( string indexName, string columnName ) |
Visual Basic (Declaration) |
---|
Public Sub New ( _ indexName As String, _ columnName As String _ ) |
Parameters
- indexName
- Type: System..::.String
The index name.
- columnName
- Type: System..::.String
The name of the Column to index.
Remarks
The following properties use their default values:
- IsUnique property is set to falseFalsefalsefalse (False in Visual Basic).
- IsAscending property is set to trueTruetruetrue (True in Visual Basic).
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. A new Index object is created for the
specified Column which has the same index name but prefixed by "idx_". The Index is then added to the IndexCollection
using the IndexCollection.Add method.
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