使用contextmenu从列表视图复制所选项目 [英] Copy selected item from listview using contextmenu
问题描述
我正在尝试从列表视图中复制所选项目并使用上下文菜单将其粘贴到另一个文本框中。
我尝试过:
I am trying to copy selected item from listview and pasting it in another text box using context menu.
What I have tried:
private void mnuPaste_click(object sender, EventArgs e)
{
IDataObject idata = Clipboard.GetDataObject();
if(idata.GetDataPresent(DataFormats.Text))
{
txtdemo.text=(String)idata.GetData(DataFormats.Text);
}
}
我尝试将代码粘贴到文本中。我可以将文本粘贴到另一个文本框中。我无法从列表视图中复制该项目。
我跟着 https://www.codeproject.com/Articles/5952/用于referance的Context-Menu-for-ListView-Column-Manipulation 。它很好的信息,但无法找到获取所选项的值的信息。
I tried for the code to paste the text. And I am able to paste the text in another text box. I was not able to copy the item from listview.
I followed https://www.codeproject.com/Articles/5952/Context-Menu-for-ListView-Column-Manipulation for referance. Its nice information but could not find information to get value of selected item.
推荐答案
我正在使用.Net紧凑框架,所以我无法执行复制字符串选定的项目并将其放入剪贴板。但是现在我已经完成了。
这就是我所做的:
I am using .Net compact framework so I was unable to perform to copy the string of the selected item and put it into clipboard. But Now I have done it.
This is what I did:
private void mnuCopy_click(object sender, EventArgs e)
{
string ind1 = listView1.SelectedIndices[0].ToString();
int ind2 = Convert.ToInt16(ind1);
string item = listView1.Items[ind2].Text; //here I got the string of selected item
Clipboard.SetDataObject(item);
}
这篇关于使用contextmenu从列表视图复制所选项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!