如何设置propertyGridControl中的选项为CheckedListBox
怎么设置propertyGridControl中的选项为CheckedListBox
这是propertyGridControl对应的对象
public class MemberLevelSelect : TacticMemberSelectBase
{
public MemberLevelSelect()
{
this.tacticType = TacticTypeEnum.Target;
}
public override string ToString()
{
return "会员等级";
}
string presentChoose = string.Empty;
[EditorAttribute(typeof(ListBoxUCConverter), typeof(System.Drawing.Design.UITypeEditor)),
CategoryAttribute("会员等级选择"), DisplayName("会员等级"), DescriptionAttribute("会员等级")]
public string DefaultFileName
{
get { return presentChoose; }
set { presentChoose = value; }
}
}
我想把等级选择这个属性在propertyGridControl中显示为CheckedListBox类型.下面代码是ListBoxUCConverter的实现
public class CheckedListBoxUC : DevExpress.XtraEditors.CheckedComboBoxEdit
{
private System.Windows.Forms.Design.IWindowsFormsEditorService m_iws;
private string m_selectStr = string.Empty;
/// <summary>
/// 获取选择的字段,多个字段用"|"隔开
/// </summary>
public string SelectedFields
{
get
{
return this.m_selectStr;
}
}
public CheckedListBoxUC(System.Windows.Forms.Design.IWindowsFormsEditorService iws)
{
this.m_iws = iws;
this.Visible = true;
this.Height = 100;
//添加事件
this.Leave += new EventHandler(checkedListBoxUC_Leave);
try
{
this.Properties.Items.AddRange(new DevExpress.XtraEditors.Controls.CheckedListBoxItem[] {
new DevExpress.XtraEditors.Controls.CheckedListBoxItem(null, "1212"),
new DevExpress.XtraEditors.Controls.CheckedListBoxItem(null, "21234")});
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
this.EndUpdate();
}
}
void checkedListBoxUC_Leave(object sender, EventArgs e)
{
List<string> lstStrs = new List<string>();
for (int i = 0; i < this.Properties.Items.Count; i++)
{
if (this.Properties.Items[i].CheckState == CheckState.Unchecked)
{
lstStrs.Add(this.Properties.Items[i].ToString());
}
}
m_selectStr = string.Join("|", lstStrs.ToArray());
this.m_iws.CloseDropDown();
}
}
public class ListBoxUCConverter : 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)
{
IWindowsFormsEditorService iws = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (iws != null)
{
CheckedListBoxUC chkListBoxUC = new CheckedListBoxUC(iws);
iws.DropDownControl(chkListBoxUC);
return chkListBoxUC.SelectedFields;
}
return value;
}
}
但是结果时,我点下拉框时,下拉框闪一下就没了.求大侠帮忙
------解决方案--------------------
我算帮你帮到家了,谁让俺今天心情不错呢?你快点结贴吧
这是propertyGridControl对应的对象
public class MemberLevelSelect : TacticMemberSelectBase
{
public MemberLevelSelect()
{
this.tacticType = TacticTypeEnum.Target;
}
public override string ToString()
{
return "会员等级";
}
string presentChoose = string.Empty;
[EditorAttribute(typeof(ListBoxUCConverter), typeof(System.Drawing.Design.UITypeEditor)),
CategoryAttribute("会员等级选择"), DisplayName("会员等级"), DescriptionAttribute("会员等级")]
public string DefaultFileName
{
get { return presentChoose; }
set { presentChoose = value; }
}
}
我想把等级选择这个属性在propertyGridControl中显示为CheckedListBox类型.下面代码是ListBoxUCConverter的实现
public class CheckedListBoxUC : DevExpress.XtraEditors.CheckedComboBoxEdit
{
private System.Windows.Forms.Design.IWindowsFormsEditorService m_iws;
private string m_selectStr = string.Empty;
/// <summary>
/// 获取选择的字段,多个字段用"|"隔开
/// </summary>
public string SelectedFields
{
get
{
return this.m_selectStr;
}
}
public CheckedListBoxUC(System.Windows.Forms.Design.IWindowsFormsEditorService iws)
{
this.m_iws = iws;
this.Visible = true;
this.Height = 100;
//添加事件
this.Leave += new EventHandler(checkedListBoxUC_Leave);
try
{
this.Properties.Items.AddRange(new DevExpress.XtraEditors.Controls.CheckedListBoxItem[] {
new DevExpress.XtraEditors.Controls.CheckedListBoxItem(null, "1212"),
new DevExpress.XtraEditors.Controls.CheckedListBoxItem(null, "21234")});
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
this.EndUpdate();
}
}
void checkedListBoxUC_Leave(object sender, EventArgs e)
{
List<string> lstStrs = new List<string>();
for (int i = 0; i < this.Properties.Items.Count; i++)
{
if (this.Properties.Items[i].CheckState == CheckState.Unchecked)
{
lstStrs.Add(this.Properties.Items[i].ToString());
}
}
m_selectStr = string.Join("|", lstStrs.ToArray());
this.m_iws.CloseDropDown();
}
}
public class ListBoxUCConverter : 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)
{
IWindowsFormsEditorService iws = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (iws != null)
{
CheckedListBoxUC chkListBoxUC = new CheckedListBoxUC(iws);
iws.DropDownControl(chkListBoxUC);
return chkListBoxUC.SelectedFields;
}
return value;
}
}
但是结果时,我点下拉框时,下拉框闪一下就没了.求大侠帮忙
------解决方案--------------------
我算帮你帮到家了,谁让俺今天心情不错呢?你快点结贴吧
- C# code
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { IWindowsFormsEditorService iws = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (iws != null) { CheckedListBoxUC chkListBoxUC = new CheckedListBoxUC(iws); switch (context.PropertyDescriptor.Category) { case "会员等级选择": //给chkListBoxUC加相关项 break; case"其它": break; } iws.DropDownControl(chkListBoxUC); return chkListBoxUC.SelectedFields; } return value; }