Displaying information in messagebox from listbox

2019-03-06 16:25发布

问题:

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