I have a listview in a WinForms Form that can have 0 to 100 items and a groupbox that interacts with the currently selected item of the listview. I want to set the enabled property of the groupbox to false as soon as there is no item selected in the listview (for example if there are no items or the user clicked into a free space in the listview, unselecting the current item). I know that I could use a timer checking the Count of the selected items array but I'd like to use an event. The SelectedIndexChanged event of the listview didn't work for me. I only need an event for when there is no item selected.
Thanks for your help.
This is my SelectedIndexChanged method (that obviously won't work):
if (lstPINs.SelectedItems.Count == 0)
MessageBox.Show("Test"); // I'd disable the groupbox and return here, but this dosn't work!
int index = PINMGR.GetIndex(lstPINs.SelectedItems[0].Text);
string pin = PINMGR.GetPIN(index);
txtEditPIN1.Text = pin.Substring(0, 4);
txtEditPIN2.Text = pin.Substring(5, 4);
txtEditPIN3.Text = pin.Substring(10, 4);
txtEditPIN4.Text = pin.Substring(15, 4);
int balance = PINMGR.GetBalance(index);
// Unimportant math stuff
EDIT: The HideSelection Property is set to false, so the items will remain selected, even if the list doesn't have focus anymore. This is no problem.