<select>
How to add options at run time?
IHTMLSelectElement interface
This interface provides access to the properties and methods of the select element.
IHTMLOptionElementFactory interface
This interface creates new instances of the option element.
IHTMLOptionElement interface
This interface denotes one choice in a select block.
// get document
CComPtr<IHTMLDocument2> phtmlDoc;
if(FAILED(GetDHtmlDocument(&sphtmlDoc)) || !phtmlDoc )
return;
// get drop list
CComPtr<IHTMLSelectElement> pSelect;
if(FAILED(GetElementInterface(sID, __uuidof(IHTMLSelectElement), (void **) &pSelect)) || !pSelect)
return;
// get window to create option factory
CComQIPtr<IHTMLWindow2> pWindow;
CComPtr<IHTMLOptionElementFactory> pFactory;
if ( FAILED(pDoc->get_parentWindow(&pWindow)) || !pWindow )
return ;
if ( FAILED(pWindow->get_Option(&pFactory)) || !pFactory)
return ;
// create a new option with text passed in
IHTMLOptionElement *pOption;
VARIANT_BOOL vt_b = VARIANT_FALSE;
if(SUCCEEDED(pFactory->create(CComVariant(sVal), CComVariant(index), CComVariant(vt_b), CComVariant(vt_b), &pOption))) {
// add to combo box
pSelect->add((IHTMLElement*)pOption, CComVariant(index));
pOption->Release();
}