I am trying to work with listbox in visual stuido 2008. I am new to c# as of 2 days ago however im very experienced with c++ and batch. I was wondering if someone could give me some quick help on how to use mouse clicks.

In particular i have a form with a listbox and its populated with lots of strings. When the user clicks on one of those strings i would like to process data based on that string.

For example:
--------
| str |
| str2 |
---------

Double click str.

MessageBox.Show(str);

Ive been searching for hours and all i seem to know is that
people like to use e as a variable for EventArgs. and that you might have to use
this.MouseDoubleClick += new MouseEventHandler(Something);

im lost lol
any help ?

Recommended Answers

All 3 Replies

In design mode select your listbox. Go to the properties window(usually low right). Select events(click on the lightning bolt icon.
Scroll to MouseDoubleClick and fill in a name you like (e.g. MyMouseDblClick) Press enter and see what happens. Continue from there.

Thanks, i didnt know it was that simple :)
After making that function i was able to get the mouse click to do something. And then i came to this conclusion:
If Cfg is the name of my listbox.

public void OnDoubleClick(object sender, MouseEventArgs e)
        {
            string Value="";
            Value = Cfg.Items[Cfg.SelectedIndex].ToString();
        }

With that on click you get the name of what was clicked stored in value. Finally lol.

Thanks ddanbe

My pleasure!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.