K S Reddi Prasad

K S Reddi Prasad

  • NA
  • 28
  • 75.1k

How to disable a dynamic button in C#.net

Apr 20 2011 9:04 AM


Hi all,

        I am generating buttons in a VSTO Ribbon dynamically from the xml data. Now, I want to disable a button on a condition. Every thing seems to be correctly, but i dont know why that button is not disabling. Plz refer the following code.

                        if (docProp["IsSubmittedTDL"].Value.ToString().Equals("True"))
                        {

                        
                              // After Loading the Xml file
                        XmlNodeList groupsList = xmlDoc.DocumentElement.SelectNodes("//DocumentGenerator/Groups/Group");

                        foreach (XmlNode group in groupsList)
                        {
                            bool iterate = true;
                            rGroup = new RibbonGroup();
                            XmlNodeList buttonElements = group.SelectNodes("Buttons");
                            foreach (XmlNode buttonList in buttonElements)
                            {
                                XmlNodeList buttons = buttonList.SelectNodes("Button");
                                foreach (XmlNode button in buttons)
                                {
                                    rButton = new RibbonButton();
                                    rButton.Name = button.SelectSingleNode("ButtonId").InnerText;
                                    if (rButton.Name == "btnSubmit")
                                    {
                                        //Catch the SubmitButton and make it disable.
                                       
rButton.Enabled = false;
                                        iterate = false;
                                        break;
                                    }
                                }
                            }
                            if (iterate == false)
                                break;
                        }


 Any help will be greatly appreciated.

Thanks,
K.S.R Prasad

Answers (3)