using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.ComponentModel;

/// <summary>
/// Summary description for ComboEditor
/// </summary>

namespace ColumnEditors
{
    public class ComboEditor : GridDropDownListColumnEditor
    {
        GridDropDownColumn _owner;
        public ComboEditor(GridDropDownColumn owner)
            : base(owner)
        {
            _owner = owner;
        }

        private RadComboBox combo;
        private DropDownList list;
        private RequiredFieldValidator _reqValidator;
        private Panel panel;
        public RadComboBox ComboControl
        {
            get
            {
                return base.ComboBoxControl;
            }
        }




        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override int SelectedIndex
        {
            get { return base.SelectedIndex; }
            set
            {
                base.SelectedIndex = value;
            }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override string SelectedValue
        {
            get
            {
                return base.SelectedValue;
            }
            set
            {
                base.SelectedValue = value;
            }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override string SelectedText
        {
            get
            {
                return base.SelectedText;
            }
            set
            {
                base.SelectedText = value;
            }
        }

        protected override void AddControlsToContainer()
        {
            base.AddControlsToContainer();

            panel = new Panel() { ID = "ComboEditorPanel" };            
            ContainerControl.Controls.Add(panel);
            panel.Controls.Add(this.combo);

            _reqValidator = new RequiredFieldValidator();
            _reqValidator.ErrorMessage = "This field is required.";
            _reqValidator.ControlToValidate = this.combo.ID;
            _reqValidator.Font.Bold = true;
            _reqValidator.Display = ValidatorDisplay.Dynamic;
            
            panel.Controls.Add(_reqValidator);
        }

        protected override void LoadControlsFromContainer()
        {
            if (_owner.DropDownControlType == GridDropDownColumnControlType.RadComboBox)
            {
                combo = ContainerControl.FindControl(string.Format("RCB_{0}", this._owner.UniqueName)) as RadComboBox;
            }
            else
            {
                list = ContainerControl.FindControl(string.Format("DDL_{0}", this._owner.UniqueName)) as DropDownList;
            }
        }

        protected override void CreateControls()
        {
            base.CreateControls();
            base.ControlsCreated = true;
            combo = base.ComboBoxControl;
            combo.EnableLoadOnDemand = false;
            combo.ShowToggleImage = true;
            combo.NoWrap = false;
            combo.MarkFirstMatch = true;
            combo.AllowCustomText = false;
            combo.Skin = "Telerik";
            combo.Width = Unit.Pixel(470);

            list = base.DropDownListControl;
           
        }

 
    }          

}