文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>一个遍历页面控件ID并放入DropDown供选择的UITypeEditor

一个遍历页面控件ID并放入DropDown供选择的UITypeEditor

时间:2010-12-27  来源:零度的火

using System;
using System.Drawing.Design;
using System.Web.UI;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace MvcApp.WebForms.Controls
{
        public class IteratePageControlsUITypeEditor : UITypeEditor
        {
                public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
                {
                        return UITypeEditorEditStyle.DropDown;
                }

                public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
                {
                        IWindowsFormsEditorService service = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
                        ListBox lbValues = new ListBox();
                        lbValues.BorderStyle = BorderStyle.None;
                        IteratePageDropDownList(lbValues, context, value);
                        lbValues.Click += (sender, arg) =>
                        {
                                service.CloseDropDown();
                        };
                        service.DropDownControl(lbValues);
                        if (lbValues.SelectedItem != null)
                                return lbValues.SelectedItem.ToString();
                        else
                                return "";
                }

                private void IteratePageDropDownList(ListBox lbValues, System.ComponentModel.ITypeDescriptorContext context, object value)
                {
                        System.Web.UI.WebControls.WebControl self = context.Instance as System.Web.UI.WebControls.WebControl;
                        Page page=null;
                        if (self.Site.Container.Components.Count > 0)
                                page = self.Site.Container.Components[0] as Page;
                        int currentIndex = -1;
                        foreach (System.Web.UI.Control item in page.Controls)
                        {
                                if (item is System.Web.UI.WebControls.DropDownList == false || self.ID == item.ID)
                                        continue;
                                currentIndex = lbValues.Items.Add(item.ID);
                                if (item.ID == value.ToString())
                                        lbValues.SelectedIndex = currentIndex;
                        }
                }
        }
}
 

 

使用的时候,只需要在我的控件的属性上声明一下就可以了:

[Editor(typeof(IteratePageControlsUITypeEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string ClientDropDownListID
{
        get { return m_ClientDropDownListID; }
        set { m_ClientDropDownListID = value; }
}

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载