当前使用列表框和contextMenuStrip,在项目右键单击后,如何从列表框中检索项目的索引?如何从列表框中获取项目索引
我的功能:
private void contextMenuStripOption1_Click(object sender, EventArgs e)
{
if (listBoxFiles.SelectedIndex == -1)
{
return;
}
Point ptCursor = Cursor.Position;
int itemIndex = listBoxFiles.IndexFromPoint(ptCursor);
}
删除功能:
private void contextMenuStripDelete_Click(object sender, EventArgs e)
{
if (listBoxFiles.SelectedIndex == -1)
{
return;
}
listBoxFiles.Items.RemoveAt(listBoxFiles.SelectedIndex);
}
为什么你不能只使用listBoxFiles.SelectedIndex? – Coltech 2012-03-09 13:29:25
[C#如何选择ListBox项目与RightClick?]的可能重复(http://stackoverflow.com/questions/9229034/c-sharp-how-to-select-listbox-item-with-right-lick) – 2012-03-09 13:49:36
感谢它的帮助! – falukky 2012-03-09 13:58:40