问题
I am writing a program that requires me to select a home address from a listbox. When i click on the display button a messagebox is supposed to appear and display the address and several other bits of information stored in an array list for that address. I am fairly unfamiliar with listboxes and can't figure out how to display all this information in a messagebox from one selection in a listbox.
回答1:
You can get the selected item value in a ListBox
string curItem = listBox1.SelectedItem.ToString();
you may handle the onClick
event of your btn, then show information in a message box
MessageBox.Show (curItem );
More info for MessageBox here
回答2:
or you can write
MessageBox.Show(listBox1.SelectedItem.ToString());
no need to initialize any variable if you do not need th
来源:https://stackoverflow.com/questions/10201226/displaying-information-in-messagebox-from-listbox