Click here to Skip to main content
15,887,344 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

how to display the infomation in messagebox when i click an item, or place cursor on an item, listed in the listbox?? i am using c# visual studio 2008 (windows application)
Posted

Give the Listbox.SelectedValueChanged[^] event a try.

Initiate somewhere:
C#
listbox1.SelectedValueChanged += new EventHandler(Listbox1_SelectedValueChanged);


And implement an event handler like this
C#
Listbox1_SelectedValueChanged(object sender, EventArgs e)
{
    Listbox listbox = (Listbox)sender;

    MessageBox.Show(listbox.SelectedItem.ToString());
}
 
Share this answer
 
Click is easy: Handle the ListBox.Click event:
C#
private void myListBox_Click(object sender, EventArgs e)
    {
    ListBox lb = sender as ListBox;
    if (lb != null)
        {
        MessageBox.Show(lb.SelectedItem);
        }
    }
"place cursor on an item" is harder - what do you mean exactly?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900