// This method would be called whenever the style needs to updated
        private void dataSelectorUserControl_StyleUpdated(object sender, StyleUpdatedDataSelectorUserControlEventArgs e)
        {
            HideStyleControls();
            DataSelectorUserControl dataSelectorUserControl = sender as DataSelectorUserControl;

            LegendAdornmentLayer legendAdornmentLayer = (LegendAdornmentLayer)map.AdornmentOverlay.Layers[0];

            // Here we update the styleBuilder and UI according to the style builder type passed from the data selector user control.
            switch (e.DemographicStyleBuilderType)
            {
            case DemographicStyleBuilderType.ValueCircle:
                currentStyleBuilder             = new ValueCircleDemographicStyleBuilder();
                trackBarValueCirleRadio.Visible = true;
                lblValueCircle.Visible          = true;
                legendAdornmentLayer.Title.TextStyle.TextColumnName = e.ActivatedStyleSelectors[0].LegendTitle;
                break;

            case DemographicStyleBuilderType.DotDensity:
                currentStyleBuilder       = new DotDensityDemographicStyleBuilder();
                lblFewer.Visible          = true;
                lblMore.Visible           = true;
                trackBarDots.Visible      = true;
                lblDotDensityUnit.Visible = true;
                legendAdornmentLayer.Title.TextStyle.TextColumnName = e.ActivatedStyleSelectors[0].LegendTitle;
                break;

            case DemographicStyleBuilderType.PieChart:
                currentStyleBuilder = new PieChartDemographicStyleBuilder();
                foreach (StyleSelectorUserControl item in e.ActivatedStyleSelectors)
                {
                    ((PieChartDemographicStyleBuilder)currentStyleBuilder).SelectedColumnAliases.Add(item.Alias);
                }
                legendAdornmentLayer.Title.TextStyle.TextColumnName = dataSelectorUserControl.Title;
                break;

            case DemographicStyleBuilderType.Thematic:
            default:
                currentStyleBuilder                  = new ThematicDemographicStyleBuilder();
                lblDisplayEndColor.Visible           = true;
                lblColorWheelDirection.Visible       = true;
                cbxActiveEndColor.Visible            = true;
                cbxSelectColorWheelDirection.Visible = true;
                legendAdornmentLayer.Title.TextStyle.TextColumnName = e.ActivatedStyleSelectors[0].LegendTitle;
                lblDisplayColor.Text = "Display Start Color";
                break;
            }

            foreach (StyleSelectorUserControl activatedStyleSelector in e.ActivatedStyleSelectors)
            {
                currentStyleBuilder.SelectedColumns.Add(activatedStyleSelector.ColumnName);
            }

            // Update UI and map.
            UpdateUIControls(currentStyleBuilder);
            UpdateMap(currentStyleBuilder);
        }
        // Here we load all the nodes on the left from xml file.
        private void LoadDataSelectorUserControls()
        {
            XDocument xDocument             = XDocument.Load(@"../../App_Data/CategoryList.xml");
            IEnumerable <XElement> elements = from category in xDocument.Element("DemographicMap").Elements("Category")
                                              select category;

            Collection <DataSelectorUserControl> userControls = new Collection <DataSelectorUserControl>();

            foreach (var element in elements)
            {
                DataSelectorUserControl dataSelector = null;
                if (element.Attribute("name").Value != "Custom Data")
                {
                    dataSelector = new DataSelectorUserControl();
                }
                else
                {
                    dataSelector = new CustomDataSelectorUserControl();
                    ((CustomDataSelectorUserControl)dataSelector).DataSelected += MainForm_CustomDataSelected;
                }

                dataSelector.Title = element.Attribute("name").Value;
                dataSelector.Image = new Bitmap(string.Format("{0}{1}", "../../", element.Attribute("icon").Value));

                foreach (var item in element.Elements("item"))
                {
                    StyleSelectorUserControl styleSelector = new StyleSelectorUserControl();
                    styleSelector.ColumnName  = item.Element("columnName").Value;
                    styleSelector.Alias       = item.Element("alias").Value;
                    styleSelector.LegendTitle = item.Element("legendTitle").Value;
                    dataSelector.AddStyleSelector(styleSelector);
                }

                if (dataSelector.GetStyleSelectorCount() >= 2)
                {
                    dataSelector.PieChartEnabled = true;
                }

                dataSelector.StyleUpdated += dataSelectorUserControl_StyleUpdated;
                dataSelector.Click        += dataSelector_Click;
                flowLayoutPanel1.Controls.Add(dataSelector);
            }
            ((DataSelectorUserControl)(flowLayoutPanel1.Controls[0])).SetActiveStatus(true);
        }
        private void dataSelector_Click(object sender, EventArgs e)
        {
            DataSelectorUserControl clickedDataSelector = (DataSelectorUserControl)sender;

            foreach (DataSelectorUserControl control in flowLayoutPanel1.Controls.OfType <DataSelectorUserControl>())
            {
                if (clickedDataSelector != control && control.IsActive)
                {
                    control.SetActiveStatus(false);
                }
            }
            clickedDataSelector.SetActiveStatus(!clickedDataSelector.IsActive);
            if (!(clickedDataSelector is CustomDataSelectorUserControl))
            {
                currentFeatureLayer = censusStateFeatureLayer;
            }
            else
            {
                currentFeatureLayer = customFeatureLayer;
            }

            ((LayerOverlay)map.Overlays["DemographicLayerOverlayKey"]).Layers.Clear();
            ((LayerOverlay)map.Overlays["DemographicLayerOverlayKey"]).Layers.Add(currentFeatureLayer);
        }