PropertyGrid 用法(下拉框篇)

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

如果有在PropertyGrid中用下拉框的朋友有困难的,请参见下面。并希望高手提出意见,

说明:下面的代码是不能run的。这是直接copy了我的东西,想用的朋友,需要修一些地方.

using System;

using System.Text;

using System.Reflection;

using System.Collections;

using System.ComponentModel;

using System.Runtime.InteropServices;

using System.Data;

using System.Drawing;

using System.Drawing.Design;

namespace Com.WorkFlowEnginer.Entity

{

#region 对象下来列表控建[Role]

//对象选择下拉列表转化

public class DropDownListRoleConverter : System.Drawing.Design.UITypeEditor

{

public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)

{

return System.Drawing.Design.UITypeEditorEditStyle.DropDown;

}

public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)

{

System.Windows.Forms.Design.IWindowsFormsEditorService iws = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

if(iws!=null)

{

DropDownListRoleControll dlc = new DropDownListRoleControll(iws);

iws.DropDownControl(dlc);

return dlc.SelectString;

}

return value;

}

}

public class DropDownListRoleControll : System.Windows.Forms.ListBox

{

public DropDownListRoleControll(System.Windows.Forms.Design.IWindowsFormsEditorService iws)

{

//初始化下拉列表 此处需要修改

DataTable dt = Com.WorkFlowEnginer.RoleManager.GetRoleList();

if ( dt != null && dt.Rows.Count>0)

{

foreach(DataRow dr in dt.Rows)

{

Role role = new Role();

role.RoleGuid = dr["Guid"].ToString();

role.Name = dr["Name"].ToString();

this.Items.Add(role);

}

}

this._iws = iws;

this.Visible = true;

this.Height =100;

this.BorderStyle = System.Windows.Forms.BorderStyle.None;

//添加事件

this.SelectedValueChanged +=new EventHandler(cb_SelectedValueChanged);

}

//此处可以修改

private Com.WorkFlowEnginer.Entity.Role select = null;

public Com.WorkFlowEnginer.Entity.Role SelectString

{

get

{

return this.select;

}

}

private System.Windows.Forms.Design.IWindowsFormsEditorService _iws;

private void cb_SelectedValueChanged(object sender, EventArgs e)

{

if ( this.SelectedItem != null)

{

//此处需要修改

this.select = (Com.WorkFlowEnginer.Entity.Role)this.SelectedItem;

this._iws.CloseDropDown();

}

else

System.Windows.Forms.MessageBox.Show("无对象可得","提示",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Error);

}

}

#endregion

public class Activity

{

[

CategoryAttribute("活动属性"),

ReadOnlyAttribute(false),

BrowsableAttribute(true),

EditorAttribute(typeof(DropDownListRoleConverter),typeof(System.Drawing.Design.UITypeEditor)),

DescriptionAttribute("流程中所需要的角色的名称."),

showChinese("角色名称:")

]

//此处需要修改

public Role Role

{

get { return role;}

set { role = value;}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航