Displaying information in messagebox from listbox

一曲冷凌霜 提交于 2019-12-02 21:04:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!