快速提问:当我点击列表框中的任意位置(不点击项目)时,它会自动选择第一项,我该如何删除?我希望用户选择一个特定的项目。
谢谢!
代码:
private void FriendsLb_Click(object sender, EventArgs e)
{
var obj = FriendsLb.SelectedItem;
if (obj != null)
{
FriendsLb.MouseDown += FriendsLb_MouseDown;
}
}
private void FriendsLb_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
var item = FriendsLb.IndexFromPoint(e.Location);
if (item >= 0)
{
try {
FriendsLb.SelectedIndex = item;
userRightClick.Show(FriendsLb, e.Location);
}
catch { return; } // No item selected
}
}