实现listcontrol中选项的上移:
int nIndex = m_list.GetSelectionMark(); wstring strFile1 = m_FileList[nIndex];
wstring strFileName1 = m_FileNameList[nIndex];
wstring strFile2 = m_FileList[nIndex-1];
wstring strFileName2 = m_FileNameList[nIndex-1];
//删第nIndex项
m_list.DeleteItem(nIndex);
DeleteFile(strFile1.c_str());
//将第nIndex项插入到第nIndex-1项
m_FileList[nIndex-1] = strFile1;
m_list.InsertItem(nIndex-1,strFileName1.c_str()); nIndex--;
现在问题是比如我选中第三号,点“上移”和第二行换了一下,但再点“上移",第二行(原来的地三行)并没有和第一行换,可能是没有“选中”第二行(原来的地三行)的原因。但不知道具体应该怎么改?
int nIndex = m_list.GetSelectionMark(); wstring strFile1 = m_FileList[nIndex];
wstring strFileName1 = m_FileNameList[nIndex];
wstring strFile2 = m_FileList[nIndex-1];
wstring strFileName2 = m_FileNameList[nIndex-1];
//删第nIndex项
m_list.DeleteItem(nIndex);
DeleteFile(strFile1.c_str());
//将第nIndex项插入到第nIndex-1项
m_FileList[nIndex-1] = strFile1;
m_list.InsertItem(nIndex-1,strFileName1.c_str()); nIndex--;
现在问题是比如我选中第三号,点“上移”和第二行换了一下,但再点“上移",第二行(原来的地三行)并没有和第一行换,可能是没有“选中”第二行(原来的地三行)的原因。但不知道具体应该怎么改?
m_FileList[nIndex-1] = strFile1;
m_list.InsertItem(nIndex-1,strFileName1.c_str()); 加一行
////////////////////////////////////////////////////
m_list.SetItemState(nIndex-1,LVS_SELECTED,LVS_SELECTED); //将该行选中
没有大哥....
比如list上有:
0
1
2
三个选项,我选中第三个,就是2,第一次点“上移”,是:0
2
1
说明上移成功
但第二次再点“上移”的时候,却变成了:0
2
2
2并没有和0交换
m_list.DeleteItem(nIndex);
DeleteFile(strFile1.c_str());
//将第nIndex项插入到第nIndex-1项
m_FileList[nIndex-1] = strFile1;
m_list.InsertItem(nIndex-1,strFileName1.c_str());
UINT flag = LVIS_SELECTED|LVIS_FOCUSED;
m_list.SetItemState(nIndex,flag,flag);
nIndex--;
代码这是!
m_list.SetItemState(nIndex-1,LVS_SELECTED,LVS_SELECTED); //将该行选中