none
Two WdContentControlType.wdDropdownList Questions RRS feed

  • Question

  • I have a Word-Addin that is working with WorkItems and Fields from Team Foundation Server.  In my Add-In I have a DropdownList ContentControl for TFS Fields like "Developer Assigned To" or "Resolved By" etc. 

    Questions:

    1) I would like to be able to load a WorkItem into my Word document and initialize my Dropdown list to one of, possibly  dozens, of people in the "Developer Assigned To" list.  I do not see any ContentControl method that lets me "Set Selected Item".  I tried to set the control's range text to the value of my TFS field but that threw an exception because I'm not allowed to set the range text in a dropdown list.  Is there any way for me to position my DropDown list on a specific item?

    2) Once an item is selected in my dropdown list is there any way to "Unselect" and reset the list to a 'no item selected' state? -- Or do I need to do something such as making the first item in the list an 'empty string'?

    --Richard

    Friday, February 17, 2012 11:43 PM

Answers

  • The dropdown list content control has a DropdownListEntries member that is a collection of the items. Normally the first item, .DropdownListEntries(1), is the placeholder text (by default, "Choose an item."). The first real item is then .DropdownListEntries(2). (The control's behavior gets a little odd if you go into the control's Properties dialog and remove the placeholder; don't do that.)

    You can set the control's display with a statement like

       cc.DropdownListEntries(idx).Select

    where idx is an integer you choose according to what you want to show -- just remember to add 1 to the index if you're searching an array.

    To unselect, just use cc.DropdownListEntries(1).Select to choose the placeholder text.

    It's also useful to know that the control has a read-only boolean member, .ShowingPlaceholderText, that is true if the placeholder is selected and false otherwise.


    Jay Freedman
    MS Word MVP  FAQ: http://word.mvps.org

    Saturday, February 18, 2012 5:27 PM