none
Word 2007 - DropDownList not showing items RRS feed

  • Question

  • Hi all,

    I have a DropDownList ContentControl in a Word 2007 Add-In.  In C# code I loaded the control with a list of AreaPath nodes from a Team Foundation project. 

    After loading the items ARE in the DropDownListItems collection - the collection has a a count of 97 items and if I loop through the collection in the debugger I can see that the correct data is in the collection.  Also in the debugger I can see that the control's type IS WdDropDownList

    But the drop down is not showing when I click on the control in my Word document...

    Anybody have any ideas?

    Tuesday, January 31, 2012 1:12 AM

Answers

  • Hi Richard

    The code below worked fine for me. Of course, we can't be sure that the content control object you're passing to LoadNodeCollection is the one you're looking at where you don't find the list...

           private void AddDD_List_Click(object sender, RibbonControlEventArgs e)
            {
                Word.ContentControl cc = Globals.ThisDocument.ContentControls[1];
                AddDD_Entries(cc, "top",6);
            }
            private void AddDD_Entries(Word.ContentControl cc, string ext, int factor)
            {
                int j = 0;
                for (int i=1; i<=100; i++)
                {
                    j = j + factor;
                    cc.DropdownListEntries.Add(j.ToString()+ext, j.ToString()+ext);
                }
            }
    

     


    Cindy Meister, VSTO/Word MVP
    Sunday, February 5, 2012 4:47 PM
    Moderator
  • I found it:  The behavior is by design.  For both the ComboBox and DropdownList ContentControls the items in the list will not be displayed if the control has been set to "cc.Locked = true;"

    Friday, February 17, 2012 11:40 PM

All replies

  • Hi Richard

    Please show us the code involved...


    Cindy Meister, VSTO/Word MVP
    Tuesday, January 31, 2012 12:38 PM
    Moderator
  • For whatever good you think it will do here's some code.  In the code below I have a member variable named "project" which is referencing an open TFS project.

    I hooked the "ContentControlEnter" event - no code added, just a hook so I could put a watch on the contentControl.  When the enter event fires a debugger watch of the content control shows that the contentControl.Type is WdContentControlType.wdContentControlDropdownList and the contentControl.DropdownListEntries.Count  is 94 - but in Word I get no scrollbar and the list appears empty???

    		public void LoadIterationRootNodes(Microsoft.Office.Interop.Word.ContentControl contentControl)
    		{
    			contentControl.DropdownListEntries.Clear();
    			LoadNodeCollection(contentControl, project.IterationRootNodes);
    		}
    
    		void LoadNodeCollection(Microsoft.Office.Interop.Word.ContentControl contentControl, NodeCollection nodeCollection)
    		{
    			foreach (Node node in nodeCollection)
    			{
    				contentControl.DropdownListEntries.Add(node.Path, node.Path);
    				if (node.ChildNodes.Count > 0)
    				{
    					LoadNodeCollection(contentControl, node.ChildNodes);
    				}
    			}
    		}
    
    


     

    Tuesday, January 31, 2012 6:24 PM
  • Hi Richard

    The code below worked fine for me. Of course, we can't be sure that the content control object you're passing to LoadNodeCollection is the one you're looking at where you don't find the list...

           private void AddDD_List_Click(object sender, RibbonControlEventArgs e)
            {
                Word.ContentControl cc = Globals.ThisDocument.ContentControls[1];
                AddDD_Entries(cc, "top",6);
            }
            private void AddDD_Entries(Word.ContentControl cc, string ext, int factor)
            {
                int j = 0;
                for (int i=1; i<=100; i++)
                {
                    j = j + factor;
                    cc.DropdownListEntries.Add(j.ToString()+ext, j.ToString()+ext);
                }
            }
    

     


    Cindy Meister, VSTO/Word MVP
    Sunday, February 5, 2012 4:47 PM
    Moderator
  • I found it:  The behavior is by design.  For both the ComboBox and DropdownList ContentControls the items in the list will not be displayed if the control has been set to "cc.Locked = true;"

    Friday, February 17, 2012 11:40 PM
  • I found it:  The behavior is by design.  For both the ComboBox and DropdownList ContentControls the items in the list will not be displayed if the control has been set to "cc.Locked = true;"


    Ah, OK, that makes sense :-) If the user isn't allowed to change it, the list won't be displayed. Glad you managed to track it down!

    Cindy Meister, VSTO/Word MVP

    Saturday, February 18, 2012 6:03 AM
    Moderator