移动列表控件 [英] Move in list control
本文介绍了移动列表控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在clistcontrol中上下移动所选行而不删除,并确保在选择按钮时它会向上移动。请告诉我。
我的尝试:
LVITEM lvi;
how to move selected row in clistcontrol up and down without deleting and make sure that it will gove down upt olast while selecting button ..please let me know.
What I have tried:
LVITEM lvi;
推荐答案
您好,
对于以前版本的MFC,我使用了SetSel和SetTopndex函数。
显示这个函数的帮助。
还有很多篇幅关于CListCtrl。
祝你好运
Hi,
For previous version of MFC, I used the functions SetSel and SetTopndex.
Show help for this functions.
There are also many articlehere about CListCtrl.
Best regards
如果不删除,就无法做到这一点。你必须在新的loaction创建一行副本并删除初始行。
在网上搜索clistctrl move item up down会给你举例:
复制/在CListCtrl中移动行 [ ^ ]
c ++ - 在列表框中向上或向下移动项目 - Stack Overflow [ ^ ]
要移动物品一步就可以换货:
- 获取选定索引处的项目,并将数据存储在变量
- 在新位置获取项目(索引+/- 1)并将数据存储在变量中
- 在选定位置设置项目来自新职位的数据
- 使用所选位置的数据在新位置设置项目
- 将选择更改为新位置
It is not possible to do this without deleting. You have to create a copy of the row at the new loaction and delete the initial row.
Searching the web for "clistctrl move item up down" gives you examples:
Copying/Moving Rows in CListCtrl[^]
c++ - Move an item up or down in a list box - Stack Overflow[^]
To move items one step it would be possible to exchange them:
- Get item at selected index and store data in variable
- Get item at new position (index +/- 1) and store data in variable
- Set item at selected position with data from new position
- Set item at new position with data from selected position
- Change selection to new position
// Single row must be selected
if (1 != GetSelectedCount())
return;
int sel = GetNextItem(-1, LVNI_SELECTED);
// Move up or down
int next = bUp ? sel - 1 : sel + 1;
if (next < 0 || next >= GetItemCount())
return;
CString strSel, strNext;
for (int i = 0; i < GetHeaderCtrl()->GetItemCount(); i++)
{
strSel = GetItemText(sel, i);
strNext = GetItemText(next, i);
SetItemText(sel, i, strNext);
SetItemText(next, i, strSel);
}
// Move selection
SetItemState(sel, ~LVNI_SELECTED, LVIS_SELECTED);
SetItemState(next, LVNI_SELECTED, LVIS_SELECTED);
SetSelectionMark(next);
[/ EDIT]
这篇关于移动列表控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文