Buttons
-
I have a button that when clicked the total of set of figures in a listbox is displayed in a textbox. How can I disable that button so that if there is nothing in the listbox and it is clicked, my program does not crash, and it is enabled again when there are contents in the listbox.
-
I have a button that when clicked the total of set of figures in a listbox is displayed in a textbox. How can I disable that button so that if there is nothing in the listbox and it is clicked, my program does not crash, and it is enabled again when there are contents in the listbox.
-
listbox.Items.Count will give you the number of items in the listbox. button.Enabled enables/disables the button.
Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush
index = listbox1.SelectedIndex listbox1.Items.RemoveAt(index) The above code is used to remove an item from the listbox. I have tried listbox1.items.count but program still crashed when button was clicked and there were no items in the listbox
-
index = listbox1.SelectedIndex listbox1.Items.RemoveAt(index) The above code is used to remove an item from the listbox. I have tried listbox1.items.count but program still crashed when button was clicked and there were no items in the listbox
It's pretty obvious that this code isn't going to work if there are no items in the listbox. listbox1.SelectedIndex will be -1 if there are no items in the list. Don't execute the second line of code if this is the case.
Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush
-
It's pretty obvious that this code isn't going to work if there are no items in the listbox. listbox1.SelectedIndex will be -1 if there are no items in the list. Don't execute the second line of code if this is the case.
Paul Marfleet "No, his mind is not for rent To any God or government" Tom Sawyer - Rush
Is there a line of code I can use then if index = listbox1.SelectedIndex listbox1.Items.RemoveAt(index) is used, so that the program does not crash when index =-1 I tried using an if statement: if listbox1.selectedindex =-1 then msgbox(" "), but it still crashed.
-
Is there a line of code I can use then if index = listbox1.SelectedIndex listbox1.Items.RemoveAt(index) is used, so that the program does not crash when index =-1 I tried using an if statement: if listbox1.selectedindex =-1 then msgbox(" "), but it still crashed.