如果有在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;}
}
}