NAEngine.frmLoadLocations.PopulateInputDataComboBox C# (CSharp) Method

PopulateInputDataComboBox() private method

private PopulateInputDataComboBox ( IMapControl3 mapControl, IDataLayer dataLayer ) : void
mapControl IMapControl3
dataLayer IDataLayer
return void
		private void PopulateInputDataComboBox(IMapControl3 mapControl, IDataLayer dataLayer)
		{
			esriGeometryType targetGeoType = GetDataLayerGeometryType(dataLayer);

			IEnumLayer sourceLayers = null;
			ILayer sourceLayer = null;
			IDisplayTable sourceDisplayTable = null;
			UID searchInterfaceUID = new UID();

			if (targetGeoType != esriGeometryType.esriGeometryNull)
			{
				// Only include layers that are of type IFeatureLayer
				searchInterfaceUID.Value = typeof(IFeatureLayer).GUID.ToString("B");
				sourceLayers = mapControl.Map.get_Layers(searchInterfaceUID, true);

				// iterate over all of the feature layers
				sourceLayer = sourceLayers.Next();
				while (sourceLayer != null)
				{
					// Verify that the layer is a feature layer and a display table
					IFeatureLayer sourceFeatureLayer = sourceLayer as IFeatureLayer;
					sourceDisplayTable = sourceLayer as IDisplayTable;
					if ((sourceFeatureLayer != null) && (sourceDisplayTable != null))
					{
						// Make sure that the geometry of the feature layer matches the geometry
						//   of the class into which we are loading
						IFeatureClass sourceFeatureClass = sourceFeatureLayer.FeatureClass;
						esriGeometryType sourceGeoType = sourceFeatureClass.ShapeType;
						if ((sourceGeoType == targetGeoType) ||
						   (targetGeoType == esriGeometryType.esriGeometryPoint && sourceGeoType == esriGeometryType.esriGeometryMultipoint))
						{
							// Add the layer name to the combobox and the layer to the list
							cboInputData.Items.Add(sourceLayer.Name);
							m_listDisplayTable.Add(sourceDisplayTable);
						}
					}

					sourceLayer = sourceLayers.Next();
				}
			}
			// The layer being loaded into has no geometry type
			else
			{
				// Find all of the standalone table that are not part of an NALayer
				IStandaloneTableCollection sourceStandaloneTables = mapControl.Map as IStandaloneTableCollection;
				IStandaloneTable sourceStandaloneTable = null;
				sourceDisplayTable = null;

				int count = 0;
				if (sourceStandaloneTables != null)
					count = sourceStandaloneTables.StandaloneTableCount;

				for (int i = 0; i < count; ++i)
				{
					sourceStandaloneTable = sourceStandaloneTables.get_StandaloneTable(i);
					sourceDisplayTable = sourceStandaloneTable as IDisplayTable;

					if ((sourceStandaloneTable != null) && (sourceDisplayTable != null))
					{
						// Add the table name to the combobox and the layer to the list
						cboInputData.Items.Add(sourceStandaloneTable.Name);
						m_listDisplayTable.Add(sourceDisplayTable);
					}
				}

				// Find all of the standalone tables that are part of an NALayer
				searchInterfaceUID.Value = typeof(INALayer).GUID.ToString("B");
				sourceLayers = mapControl.Map.get_Layers(searchInterfaceUID, true);

				sourceLayer = sourceLayers.Next();
				while (sourceLayer != null)
				{
					INALayer sourceNALayer = sourceLayer as INALayer;
					if (sourceNALayer != null)
					{
						sourceStandaloneTables = sourceNALayer as IStandaloneTableCollection;
						sourceStandaloneTable = null;
						sourceDisplayTable = null;

						count = 0;
						if (sourceStandaloneTables != null)
							count = sourceStandaloneTables.StandaloneTableCount;

						for (int i = 0; i < count; ++i)
						{
							sourceStandaloneTable = sourceStandaloneTables.get_StandaloneTable(i);
							sourceDisplayTable = sourceStandaloneTable as IDisplayTable;

							if ((sourceStandaloneTable != null) && (sourceDisplayTable != null))
							{
								// Add the table name to the combobox and the layer to the list
								cboInputData.Items.Add(sourceStandaloneTable.Name);
								m_listDisplayTable.Add(sourceDisplayTable);
							}
						}
					}

					sourceLayer = sourceLayers.Next();
				}
			}
		}