我想我有一个可行的解决方案。本例中的模型对象类型为“Item”。有关一些解释,请参阅代码注释。
private List<Item> _MultiSelectList;
public Form1() {
_MultiSelectList = new List<Item>();
}
private void objectListView1_MouseClick(object sender, MouseEventArgs e) {
objectListView1.BeginUpdate();
if (objectListView1.MouseMoveHitTest.Item != null) {
var item = objectListView1.MouseMoveHitTest.Item.RowObject as Item;
if (item != null) {
if (_MultiSelectList.Contains(item)) {
_MultiSelectList.Remove(item);
} else {
_MultiSelectList.Add(item);
}
}
}
objectListView1.SelectObjects(_MultiSelectList);
objectListView1.EndUpdate();
}
private void objectListView1_MouseDown(object sender, MouseEventArgs e) {
objectListView1.Freeze();
}
private void objectListView1_MouseUp(object sender, MouseEventArgs e) {
objectListView1.Unfreeze();
}