Select to view content in your preferred language

Multiple message boxes appear when there should only be one.

1065
0
08-29-2012 05:51 AM
RobertDouglas
Emerging Contributor
Hi,

So this one is not too big of a problem but rather a mild annoyance. I have an Add-In built with C# that requires the user to have a layer selected for the a query of its attributes to be run based on the input in a combo box. In the add-in there are 2 combo boxes. One where the choices are set as a drop down and one where the user can type in characters. If the user has not selected a layer or has selected the wrong layer a message box prompts them to select the appropriate layer. When the user is interacting with the combo box where they type in information the message box has the expected results, but when interacting with the drop down three message boxes appear, one after another and each must be ok'ed to continue. The way the ArcMap UI refreshes between each message box is of note. The first message box appears when an item in the drop down is selected. When this one is ok'ed the drop down collapses and then the second message box appears, but the combo box is still selected. After the second is ok'ed the combo box is unselected and the third message box appears. No, change is noticed when the third is ok'ed.

When I put in a break point at the message box and step through it, it goes through the messagebox twice and then to the OnUpdate for the other combobox, then the OnUpdate for the combobox with the drop down, then sometimes it gets hung other times the frame of the message box appears and then after steping through the OnUpdate for both comboboxes one after the other several times the rest of the message box appears. Sometimes it steps through to a point where I can ok it other times it gets hung at this point, and still other times there is no message box at all. Occasionally, I get two message boxes while stepping through and then get hung after the second, or I get bounced back and forth between the OnUpdates indefinitely. Below is the code for the drop down combo box class.

        protected override void OnSelChange(int cookie)
        {
            if (ArcMap.Document.SelectedLayer == null)
            {
                MessageBox.Show("Select a school layer");
                //return;
            }
            else if (ArcMap.Document.SelectedLayer != null)
            {
                string layer;
                layer = Convert.ToString(ArcMap.Document.SelectedLayer.Name);

                if (layer != "DOE_School_organizations" && layer != "DOE_School_sites" && layer != "NYC_Non_public_schools")
                {
                    MessageBox.Show("Select a school layer");
                    //return;
                }

                else
                {
                    // The value property provides the selected item.
                    switch (Value)
                    {
                        case "Borough":
                            {
                                break;
                            }
                        case "Manhattan":
                            {
                                dGSchool.Rows.Clear();
                                clearCursor();
                                array.RemoveAll();

                                cityName = "'NEW YORK' Or City = 'ROOSEVELT ISLAND'";
                                boroCode = Convert.ToString(1);
                                setBoroCode();

                                SelectMapFeaturesByAttributeQuery(ArcMap.Document.ActiveView as IActiveView, ArcMap.Document.SelectedLayer as IFeatureLayer, whereClause);

                                GetFeatureClassOfSelectedFeatureLayer(ArcMap.Document.SelectedLayer as IFeatureLayer);

                                PerformAttributeQuery(featureClass, whereClause);

                                WinSchoolZoom.setDG2();

                                setSelectedLayer(Convert.ToString(ArcMap.Document.SelectedLayer.Name));
                                break;

                            }
                        case "Bronx":
                            {
                                dGSchool.Rows.Clear();
                                clearCursor();
                                array.RemoveAll();

                                cityName = "'BRONX' Or City = 'RIVERDALE'";
                                boroCode = Convert.ToString(2);
                                setBoroCode();

                                SelectMapFeaturesByAttributeQuery(ArcMap.Document.ActiveView as IActiveView, ArcMap.Document.SelectedLayer as IFeatureLayer, whereClause);

                                GetFeatureClassOfSelectedFeatureLayer(ArcMap.Document.SelectedLayer as IFeatureLayer);

                                PerformAttributeQuery(featureClass, whereClause);

                                WinSchoolZoom.setDG2();

                                setSelectedLayer(Convert.ToString(ArcMap.Document.SelectedLayer.Name));
                                break;
                            }
                      
...


        protected override void OnUpdate()
        {

        }

Thanks for any insight,
Robbie
0 Kudos
0 Replies