110,561
社区成员
发帖
与我相关
我的任务
分享
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedIndices.Count > 0)
{
//有选中项,这里设右键某项可用
}
else
{
//无选中项,这里设右键某项不可用
}
}
if (listView1.SelectedItems.Count != 0)
{
foreach (ListViewItem lv in listView1.SelectedItems)
lv.Remove();
}
private void lbc_MouseUp(object sender, MouseEventArgs e)
{
if (_havedo && lbc.SelectedItem != null && e.Button == MouseButtons.Right)
{
int posindex = lbc.IndexFromPoint(new Point(e.X, e.Y));
if (posindex >= 0 && posindex < lbc.Items.Count)
{
lbc.SelectedIndex = posindex;
pm.ShowPopup(Control.MousePosition);
}
}
}
先判断鼠标点中的是不是空白,不是空白就弹出
private void listView1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
var hitTestInfo = listView1.HitTest(e.X, e.Y);
if (hitTestInfo.Item != null)
{
var loc = e.Location;
loc.Offset(listView1.Location);
// Adjust context menu (or it's contents) based on hitTestInfo details
this.contextMenuStrip2.Show(this, loc);
}
}
}