Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C++
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
Posted
Updated 6-Jun-17 20:52pm
v3
Comments
Kornfeld Eliyahu Peter 6-Jun-17 12:48pm    
Have you used the debugger to understand what the run-time values are and what actually happening in your code?

1 solution

You have to change also the selection because after exchanging the content the lower item is still selected.

Add this at the end of your handler:
// 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);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900