Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Select and Move Multiple items (Move up/Move Down) within treeview con

keegankeegan Member Posts: 1
Hi,
im trying to select multiple items in treeview and want to move up and move down within the treeview.I'd tried to modify some codes from drag and drop functionality but it doesnt work.For now this piece of code only can make single movement.please guide me on this...Thanks!

Heres my code:-


void xyz::OnMoveDown()
{
tree.MoveDown(tree.GetSelectedItem());
}

void xyz ::MoveDown(HTREEITEM hItem)

{
if (hItem == NULL)
return;

HTREEITEM hUpItem = GetNextSiblingItem(hItem);

if (hUpItem != NULL)
{
char szLabel[256];
TV_ITEM tvi;
TV_INSERTSTRUCT tvis;

tvi.hItem = hItem;
tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_HANDLE | TVIF_PARAM;
tvi.pszText = szLabel;
tvi.cchTextMax = 255;

// get item that was dragged
if (!GetItem (&tvi))
return;

tvis.hParent = GetParentItem(hItem);

HTREEITEM hUpItem2 = GetPrevSiblingItem(hUpItem);

if (hUpItem2 == NULL)
tvis.hInsertAfter = TVI_FIRST;
else
tvis.hInsertAfter = hUpItem;

tvis.item = tvi;

HTREEITEM hNewItem = CopyRecursive(hItem, &tvis, &tvi);
ASSERT(hNewItem);

// remove moved item
DeleteItem(hItem);

CWnd* pParent = GetParent();
if (pParent != NULL)
{
pParent->SendMessage(
nTreeSelItems,
(WPARAM)this, (LPARAM)hItem);
}

// select the new item we just inserted
VERIFY(SelectItem(hNewItem));
}
}


HTREEITEM xyz::CopyRecursive(HTREEITEM hItem, TV_INSERTSTRUCT *pTVIS, TV_ITEM *pTVI)

{
// insert item into CTreeCtrl
HTREEITEM hNewItem = InsertItem(pTVIS);

ASSERT(hNewItem);

// if we have inserted a non leaf node, insert all children too
if (ItemHasChildren(hItem))
{
HTREEITEM hChildItem = GetChildItem(hItem);

while (hChildItem != NULL)
{
// get child of item that was dragged
pTVI->hItem = hChildItem;

VERIFY(GetItem(pTVI));

pTVIS->item = *pTVI;
pTVIS->hParent = hNewItem;
pTVIS->hInsertAfter = TVI_LAST;

CopyRecursive(hChildItem, pTVIS, pTVI);

hChildItem = GetNextItem(hChildItem, TVGN_NEXT);
}

TVITEM tvItem;
tvItem.hItem = hItem;
tvItem.mask = TVIF_STATE;
tvItem.stateMask = TVIS_EXPANDED;
SendMessage(TVM_GETITEM, 0, (LPARAM)(&tvItem));

if (tvItem.state & TVIS_EXPANDED)
// expand inserted item
VERIFY(Expand (hNewItem, TVE_EXPAND));
}

return hNewItem;
}

Sign In or Register to comment.