Thomas Morrison

Thomas Morrison

  • NA
  • 10
  • 19.1k

Bind listbox selected item focus to button enabled

Sep 11 2010 11:14 AM
Hi, I have a listbox which I want the users to be able to remove items from when they select an item then click the delete button. However an error will occur if you try to click remove when having nothing in the list box selected.

lstToSearch.Items.RemoveAt(lstToSearch.SelectedIndex);

 Now in the "olden days" I would have to into events such as SelectionChange and have btnRemove.Enabled = True, but I'm sure there must be a more elegant way with data bindings? Am I right?

So to recap, when the user selects an item on the listbox, the remove button becomes enabled. When no item is selected the remove button is disabled

Thanks
Thomas

Answers (2)