developer
developer

Reputation: 11

Disable an item in the combobox: devexperss winforms

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);

when i open the application,i will check for some value.if vaule is false the button "orange " should be disabled.How to achieve this.

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

Upvotes: 0

Views: 264

Answers (1)

Marko Juvančič
Marko Juvančič

Reputation: 5890

ComboBox edit doesn't support this functionality. However I would try handling DrawItem and CloseUp events.

Something like this:

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);
}

Upvotes: 1

Related Questions