本文介绍了上/下功能在listcontrol中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的列表中有一些项目(动态数据)

当我在列表中选择一个项目并点击向上时。按钮正确地向上移动(fisrt time click)但是如果再次点击向上按钮则会恢复更改(我的意思是如果再点击一次按钮就不会发生它正在发生的恢复)

你能不能帮我这里



我尝试过的事情:



i have some items in my list(dynamic data)
when i selected an item in the list and clicked on 'up'. button its wmoving up correctly(fisrt time clicking)but if click up button again then it is reverting changes( i mean if click one more time up button it not happening up its happening reverting)
could you please help me here

What I have tried:

int item2 = m_clistctrl.GetNextItem(-1, LVNI_SELECTED);// i think problem is in this line because its always considering selected one is intially selected thing
int columns = m_clistctrl.GetHeaderCtrl()->GetItemCount();

for (int i = 1; i < columns; i++)
{
  CString str1 = m_clistctrl.GetItemText(item2 - 1, i);
  CString str2 = m_clistctrl.GetItemText(item2, i);

  m_clistctrl.SetItemText(item2 - 1, i, str2);
  m_clistctrl.SetItemText(item2, i, str1);
}



首先点击它的工作正常但是如果我再次点击它不会上升它的下来

可以请告诉我在这段代码中有什么问题


for first clicking its working fine but if i click it again its not going up its coming down
could please tell me anything wrong in this code

推荐答案

// Unselect item2 (the lower one)
m_clistctrl.SetItemState(item2, ~LVIS_SELECTED, LVIS_SELECTED);
// Select the upper item
m_clistctrl.SetItemState(item2 - 1, LVIS_SELECTED, LVIS_SELECTED);
// This is only necessary if there are multiple items selected
m_clistctrl.SetSelectionMark(item2 - 1);


这篇关于上/下功能在listcontrol中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 01:41