Viewer user control

Land Desktop Map 3D Samples

 
Viewer user control
 
 
 

The Viewer user control consists of a data grid control and a series of controls on a tool strip. When first created, the user control performs the following actions:

  1. Instantiate a global object representing a single cell and set its color. Later this cell will be used as a template for those cells in the data view that hold information that cannot be modified.
  2. Call UpdateLayersComboBox. This function calls the GetLayerNames function, which uses the AcMapMap.GetCurrentMap API method to get the current AcMapMap object, loops through all layers in that object, builds a string array with the names of each of the layers, and returns the string array. UpdateLayersComboBox then adds the names in the string array to the cbLayers combo box, which is on the tool strip.

The following are the actions taken by the Viewer user control in response to user input:

  • EditSetViewer - Resize event.
    1. Resize the data grid to correctly fit within the new window size.
  • btnRefreshLayers - Click event
    1. Calls UpdateLayersComboBox, which clears the cbLayers combo box and fills it with a new list of all the layers in the current Map document.
  • cbLayers - Selected Value Changed event
    1. Calls the UpdateFeatureGrid method to redraw the dataGridFeatures data grid using features from the newly selected layer name. UpdateFeatureGrid first gets the current AcMapMap map object using the AcMapMap.GetCurrentMap API method. It then loops through all the layers in the AcMapMap map object to find the one with the same name as the item selected in the cbLayers combo box. When it finds the right layer object, it then calls that layer’s GetIdsOfEditSetFeatures method which returns a collection of properties for a series of features. It then calls the BuildDataTable function.
    2. BuildDataTable fills the data grid with information from the collection of features. First, it creates a Windows DataTable object to store the data in. It then gets the class definition for the selected layer. The list of identity properties is retrieved from the class definition. A loop adds a new column in the data grid for each identity property. The list of regular properties is then retrieved from the class definition, and a loop similarly adds a new column in the data grid for each regular property. BuildDataTable then loops through each individual feature’s properties from the collection of all feature’s properties returned from GetIdsOfEditSetFeatures. A query filter is created by adding together all the property names with a string containing the “AND” operator. The filter is used in a query sent to the layer object using the SelectFeatures API method, and the results of the query are returned in a MgFeatureReader object. The data values for each of the properties in the MgFeatureReader are then added to a row of the data table. When this process is complete, the data table object is returned.
    3. Calls SetDataSource with the data table returned from BuildDataTable. This function sets the data source of the dataGridFeatures data grid view control to the data table. It also changes all cells in columns containing read-only data to the style specified by the global ReadOnlyCellStyle object.