Disable/Enable button based on listtbox selection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form with a listbox and a set of command buttons.
The contents of the listbox are dynamic and are affected by command buttons
being pressed.
Some of the command buttons affect whether an item is selected or not.
I need to enable/disable a command button based on whether a selection
exists in the listbox. This enabling/disablinmg needs to happen when a
different command button is pressed. e.g.
When button A pressed, if listbox has a selection, enable button B else
disable button B
 
mscertified said:
I have a form with a listbox and a set of command buttons.
The contents of the listbox are dynamic and are affected by command buttons
being pressed.
Some of the command buttons affect whether an item is selected or not.
I need to enable/disable a command button based on whether a selection
exists in the listbox. This enabling/disablinmg needs to happen when a
different command button is pressed. e.g.
When button A pressed, if listbox has a selection, enable button B else
disable button B


I'm not very good with list boxes, but I think you only have
to test the list box's ListIndex, which will be -1 if
nothing is selected.

Me.cmdbutton.Enabled = (Me.listbox.ListIndex >= 0)
 
Back
Top