示例#1
0
        private void _options_OnInsertHandler(int index, object value)
        {
            Interop.IHTMLElement selectElement = (Interop.IHTMLElement)base.GetBaseElement();
            Interop.IHTMLDOMNode selNode       = (Interop.IHTMLDOMNode)selectElement;
            Interop.IHTMLDOMNode optGrpNode    = null;
            switch (value.GetType().Name)
            {
            case "OptionElement":
                // add OPTION directly...
                optGrpNode = selNode.appendChild((Interop.IHTMLDOMNode)((OptionElement)value).GetBaseElement());
                // ...and handle InnerText separatly because this is not a real attribute
                //((Interop.IHTMLElement) optGrpNode).SetInnerText(((OptionElement) value).text);
                //optGrpNode.nodeValue = ((OptionElement) value).text;
                break;

            case "OptGroupElement":
                // add OPTGROUP and the OPTION children the element already has
                OptGroupElement optGrpObj = (OptGroupElement)value;
                optGrpNode = selNode.appendChild((Interop.IHTMLDOMNode)(optGrpObj).GetBaseElement());
                if (optGrpObj.Options != null && optGrpObj.Options.Count > 0)
                {
                    foreach (OptionElement oe in optGrpObj.Options)
                    {
                        optGrpNode.appendChild((Interop.IHTMLDOMNode)oe.GetBaseElement());
                    }
                }
                break;
            }
        }
示例#2
0
        private void CreateOptionList(Interop.IHTMLSelectElement s)
        {
            if (_options == null)
            {
                _options = new OptionElementsCollection(s, base.HtmlEditor);
                _options.OnInsertHandler += new CollectionInsertHandler(_options_OnInsertHandler);
                _options.OnClearHandler  += new CollectionClearHandler(_options_OnClearHandler);
            }
            else
            {
                Debug.WriteLine("Recreate List");
                _options.OnInsertHandler -= new CollectionInsertHandler(_options_OnInsertHandler);
                _options.OnClearHandler  -= new CollectionClearHandler(_options_OnClearHandler);
                _options.Clear();
                Interop.IHTMLElement           selectElement = (Interop.IHTMLElement)s;
                Interop.IHTMLElementCollection options       = (Interop.IHTMLElementCollection)selectElement.GetChildren();
                for (int i = 0; i < options.GetLength(); i++)
                {
                    Interop.IHTMLElement el = (Interop.IHTMLElement)options.Item(i, i);
                    IOptionElement       oe = null;
                    switch (el.GetTagName())
                    {
                    case "OPTION":
                        oe = new OptionElement(el, base.HtmlEditor);
                        break;

                    case "OPTGROUP":
                        oe = new OptGroupElement(el, base.HtmlEditor);
                        break;
                    }
                    if (oe != null)
                    {
                        _options.Add(oe);
                    }
                }
                _options.OnInsertHandler += new CollectionInsertHandler(_options_OnInsertHandler);
                _options.OnClearHandler  += new CollectionClearHandler(_options_OnClearHandler);
            }
        }
        internal OptionElementsCollection(Interop.IHTMLSelectElement s, IHtmlEditor editor) : base()
        {
            selectElement = (Interop.IHTMLElement)s;
            Interop.IHTMLElementCollection options = (Interop.IHTMLElementCollection)selectElement.GetChildren();
            for (int i = 0; i < options.GetLength(); i++)
            {
                Interop.IHTMLElement el = (Interop.IHTMLElement)options.Item(i, i);
                object oe = null;
                switch (el.GetTagName())
                {
                case "OPTION":
                    oe = new OptionElement(el, editor);
                    break;

                case "OPTGROUP":
                    oe = new OptGroupElement(el, editor);
                    break;
                }
                if (oe != null)
                {
                    InnerList.Add(oe);
                }
            }
        }