The following small series for everyone to bring a C # get the mouse in the ListView right-click the content method of the cell. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.
When we right-click the ListView control, we can get the individual text contents of the selected item.
Now we want to get only the text content of the cell when right-clicked.
Here's how:
1, define the global mouse state
Point m_mbrpt;//the right mouse button click
2. Handle the message in the ListView when the mouse is pressed
private void Listview1_mousedown (object sender, MouseEventArgs e) { // if (e.button==mousebuttons.right) { //get coordinates of the screen mouse, convert to list control coordinates M_MBRPT = listview1.pointtoclient (control.mouseposition);} }
3. Right-click menu--Copy item's message
private void Copyitem_click (object sender, EventArgs e) { //Copy the contents of the specified table cell if ( ListView1.SelectedItems.Count <= 0) { MessageBox.Show ("No transaction information selected! "," hint ", MessageBoxButtons.OK, messageboxicon.information); return; } Get the coordinates of the mouse on the screen, convert to the coordinates of the list control (to be processed and saved when the mouse is pressed) //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 Pasteboard Setclipboardtext (strText); }
4. Set the contents of the Pasteboard
public void Setclipboardtext (string strText) {try {Clipboard.setdataobje CT (strText); } catch (System.Exception ex) {MessageBox.Show (ex. Message, "Hint", MessageBoxButtons.OK, Messageboxicon.error); } }