List box Problem
-
I have a form containing two list boxes and two buttons. The form loads with a list of 50 items on Listbox1 and Listbox2 is empty. When you select an item from ListBox1 and then press Button1, the selected item is moved to ListBox2. When you select an item from List Box2 and press button2, the item is returned to ListBox1. However I want to code my program such that when the user presses button2 without selecting an item from Listbox2 , there is no program error created, but the program simply tells the user to select an item. Currently my program halts and gives me the following message box: An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll Additional information: Specified argument was out of the range of valid values. Help Me Folks Problem 2 How can I make an item that has been return back to Listbox1 appear in a different color?
-
I have a form containing two list boxes and two buttons. The form loads with a list of 50 items on Listbox1 and Listbox2 is empty. When you select an item from ListBox1 and then press Button1, the selected item is moved to ListBox2. When you select an item from List Box2 and press button2, the item is returned to ListBox1. However I want to code my program such that when the user presses button2 without selecting an item from Listbox2 , there is no program error created, but the program simply tells the user to select an item. Currently my program halts and gives me the following message box: An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll Additional information: Specified argument was out of the range of valid values. Help Me Folks Problem 2 How can I make an item that has been return back to Listbox1 appear in a different color?
1. In your Button2 click handler, write something like this: If ListBox2.SelectedItems.Count > 0 Then 'Code to move your items from ListBox2 to ListBox1 Else MsgBox("Please select an item from ListBox2") End If 2. I don't think the standard listbox supports having different fonts for its items. You may have to create your own user control for that. See example Color List Box[^].