0
我有一個ListView 3組。 我拖動一個項目從TreeView控件到ListView控件:拖動並添加項目ListView
private void listViewDemo_DragDrop(object sender, DragEventArgs e)
{
if (!is_listview) //treeview item
{
//get a text of a draged item
string str = e.Data.GetData(DataFormats.Text).ToString();
//get information about hovered item
ListViewHitTestInfo hit_info = listViewDemo.HitTest(listViewDemo.PointToClient(new Point(e.X, e.Y)));
//check position - must be on an item
if (hit_info.Location == ListViewHitTestLocations.None) return;
ListViewItem prev_item = hit_info.Item;
ListViewGroup group = prev_item.Group;
int idx = prev_item.Index;
//create a new key
Guid key = Guid.NewGuid();
string item_key = key.ToString();
//create a new item
//option 1
group.Items.Add(listViewDemo.Items.Insert(idx,item_key, str, ""));
//option2
//group.Items.Insert(idx,listViewDemo.Items.Insert(idx, item_key, str, ""));
}
}
我期待到位尖項目的添加項目,但任何選項組的末尾添加元素。 如何在鼠標懸停的地方添加項目?
非常感謝你,它非常棒! – john7
如果我想添加:list.Insert(idx + 1,item);太棒了! – john7
好極了......好像它應該在給定你的原始代碼的情況下工作,事實上,該項目進入group.Items列表中的右側插槽,但顯然渲染使用了其他優先級。 –