日期:2014-05-18  浏览次数:21163 次

怎么设置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, IServicePr