Right-click to copy the value of listview

Source: Internet
Author: User

When you right-click the listview control, you can get the text content of the selected item.

Now we only need to get the text of the cell when right-clicking. The method is as follows: 1. Define the global mouse statusPoint m_mbrpt; // when right-clicking a point 2. process the message in listview when the mouse is pressedPrivate void listviewdomainmousedown (Object sender, mouseeventargs e) {// If (E. button = mousebuttons. right) {// obtain the mouse coordinate on the screen and convert it to the coordinate mark m_mbrpt = listview1.pointtoclient (control. mouseposition );}} 3. Right-click the menu and choose "copy message ".Private void copyitem_click (Object sender, eventargs e) {// copy the content of the specified table cell if (listview1.selecteditems. Count <= 0) {MessageBox. Show ("no transaction information is selected! "," Prompt ", messageboxbuttons. OK, messageboxicon. information); return;} // obtain the coordinates of the mouse on the screen and convert them to the coordinates of the list control (process and save them when you press the mouse) // point Pt = listview1.pointtoclient (m_mbrpt); listviewitem lstrow = listview1.getitemat (m_mbrpt.x, m_mbrpt.y); system. windows. forms. listviewitem. listviewsubitem lstcol = lstrow. getsubitemat (m_mbrpt.x, m_mbrpt.y); string strtext = lstcol. text; // set to clipboard setclipboardtext (strtext );} 4. Set clipboard contentPublic void setclipboardtext (string strtext) {try {clipboard. setdataobject (strtext);} catch (system. exception ex) {MessageBox. show (ex. message, "prompt", messageboxbuttons. OK, messageboxicon. error);} content from: http://blog.sina.com.cn/s/blog_8a7012cf0101f1je.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.