简体   繁体   中英

How to trigger an event when user click on the item of the list view?

I will like to ask that I will to trigger an event which when the user click on the item in the list view then do the thing that I wished.

What is the suitable event that I can use??? Is Mouse Down event suitable???

as sthotakura stated, you would use ListView.SelectionChanged event. Link to msdn: http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.selectionchanged(v=vs.110).aspx

example:

public class doSomething
{
    public void SomeMethod()
    {
        ...
        // delegate event handler
        ListView.SelectionChanged += delegateEventHandler;

        // or Lambda Expression
        ListView.SelectionChanged += (sender, args) 
                                         => {
                                                // Apply Logic
                                            };
        ...
    }

    public void delegateEventHandler(object sender, EventArgs eventArgs)
    {
        // Apply Logic...
    }
}

Yes, it is suitable, then again GaussZ is correct. What about an user selecting this thing using his keyboard by tabbing and pressing enter or some other UI event?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM