【问题标题】:Disable an item in the combobox: devexperss winforms禁用组合框中的项目:devexperss winforms
【发布时间】:2021-10-03 20:50:30
【问题描述】:
this.Solvers.AutoHeight = false;
this.Solvers.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
this.Solvers.Items.AddRange(new object[] {
"Apple",
"Orange",
"Custom",
"Grapes"});
this.Solvers.Name = "Solvers";
this.Solvers.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
this.Solvers.EditValueChanged += new System.EventHandler(this.ricbSolvers_EditValueChanged);

当我打开应用程序时,我会检查一些值。如果 vaule 为 false,则应禁用“橙色”按钮。如何实现。

if(value==false)
{
//diable button orange
}

【问题讨论】:

  • 我不确定您要达到什么目的?阻止用户选择橙色?你为什么不直接删除它?
  • 基本上我们需要根据一些参数来启用和禁用组合框中的项目

标签: c# winforms combobox devexpress


【解决方案1】:

组合框编辑不支持此功能。不过我会尝试处理DrawItemCloseUp 事件。

类似这样的:

private void Solvers_DrawItem(object sender, ListBoxDrawItemEventArgs e) 
{
  var s = e.Item.ToString();
  var enabled = IsEnabled(s);

  if (!enabled) {
    e.Apperance.ForeColor = Color.Gray;
  }
}

private void Solvers_CloseUp(object sender, CloseUpEventArgs e) 
{
  var s = e.Value.ToString();

  e.AcceptValue = IsEnabled(s);
}

【讨论】:

    猜你喜欢
    • 2012-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 2014-01-20
    相关资源
    最近更新 更多