我有一个带DragDrop函数的ListView.我希望拖动的项目在DragDrop之后保持选中状态.
private void commandListView_DragDrop(object sender,DragEventArgs e) { Point point = commandListView.PointToClient(new Point(e.X,e.Y)); int index = 0; try { index = commandListView.GetItemAt(point.X,point.Y).Index; } catch (Exception) { } if (index < 0) { index = commandListView.Items.Count - 1; } ListViewItem data = e.Data.GetData(typeof(ListViewItem)) as ListViewItem; commandListView.Items.Remove(data); commandListView.Items.Insert(index,data); }
我试图用这个来再次选择项目,但它不起作用
data.Selected = true; data.Focused = true;
然后我测试了我是否可以专注于ListView中的第一项
commandListView.Items[0].Selected = true; commandListView.Items[0].Focused = true;
但它也没有用,选定的项目不会改变.它始终是拖动项目在拖放之前的旧索引.
PS.我正在使用WinForms
@Update
我已经尝试过了
commandListView.Focus();
但它没有奏效
只是为了澄清在同一个ListView中发生的拖拽,我拖动项目来改变他们的顺序.
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。