我在列表视图上有一个上下文菜单控件,尽管当我右键单击它时我试图在列表视图中获取所选项目的值 - 我查看了许多来源,但没有找到任何令人信服的东西
private void startCheckToolStripMenuItem_Click(object sender, EventArgs e)
{
}
只需将发件人投射到 ListBox(假设这是右键单击的内容),然后您就可以遍历选定的项目。
var lbx = sender as ListBox;
foreach (var item in lbx.SelectedItems) ...
[手键,所以可能是大写错误等]
private void listView1_MouseClick(object sender, MouseEventArgs e)
{
ListView listView = sender as ListView;
this.contextMenuStrip1.Items.Clear();
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
ListViewItem item = listView.GetItemAt(e.X, e.Y);
if (item != null)
{
this.contextMenuStrip1.Items.Add(item.Text);
item.Selected = true;
contextMenuStrip1.Show(listView, e.Location);
}
}
}