简体   繁体   中英

How do I trap a double-click event on a ListView that has no items?

In my C# app, I have a ListView on a Form. I want the user to be able to double-click on a section of the ListView when no items are selected in order to pop up a "New Item" dialog. The problem is that the DoubleClick event for the ListView only fires if an item is selected.

Is there a way to do this?

There is a way to do this, but you have to do some low-level drilling into the Windows machinery. It's generally not a good idea to spend a great deal of time trying to get a standard Windows control to behave in a non-standard manner.

A simpler way is to just put a "New Item" button next to your ListView. If screen real estate is an issue, you could just add an extra row at the bottom that says "{click here to add new item}", and show your dialog when the user clicks this last row.

为List视图的MouseDoubleClick事件添加事件处理程序。

Assuming Windows Forms:

Perhaps a good workaround would be to use a ContextMenu .

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