Moves an item to a new position.
C
LONG WINAPI SftBox_MoveItem(HWND hwndCtl, LONG from, LONG to);
C++
LONG CSftBox::MoveItem(LONG from, LONG to);
hwndCtl
The window handle of the combo box control.
from
The zero-based index of the item to be moved.
to
The zero-based index of the position where the item is to be inserted. If to is -1 (or any other value that is not a valid item index), the item is moved to the end of the list.
The return value is the zero-based index of the item at its new position or -1 if an error occurred.
The MoveItem function moves an item to a new position.
MoveItem moves all item attributes, including cell text, cell attributes, pictures, level, row header contents, etc. The value set using SetItemData is preserved. A deletion callback routine (see SetDeleteCallback) is not called for the item being moved.
The position to describes an item index before the item is moved. The item is inserted in front of the item which is at index to. As the item is removed from its original position, the index returned can differ from to.
Only the item from is moved. Its dependent items are not moved. If the item is collapsed, its dependent items are removed (the deletion callback routine is called for them). If the item is expanded, its dependent items remain at their current position.
If the item from or the item at the insertion position is hidden because a parent item is collapsed, the parent items are expanded first.
If the dropdown portion of a dropdown or dropdown list combo box is visible, it is hidden when MoveItem is called. This can be suppressed using SetRollupOnChange.
An item can be copied using the CopyItem function.
In a combo box control using a virtual data source, this function cannot be used and an error is returned.
LONG index;
GetWindowText(hwndBox, szCity, sizeof(szCity) / sizeof(szCity[0]));
if (!szCity[0])
return;
index = SftBox_FindStringExact(hwndBox, -1, 0, szCity, FALSE);
if (index > 0)
index = SftBox_MoveItem(hwndBox, index, 0);
else if (index < 0) {
index = SftBox_InsertString(hwndBox, 0, szCity);
if (SftBox_GetCount(hwndBox) > MAX_HISTORY)
SftBox_DeleteString(hwndBox, SftBox_GetCount(hwndBox) - 1);
}
SftBox_SetCurSel(hwndBox, index);
}
LONG index;
m_City.GetWindowText(city);
if (city.IsEmpty())
return;
index = m_City.FindStringExact(-1, 0, city, FALSE);
if (index > 0)
index = m_City.MoveItem(index, 0);
else if (index < 0) {
index = m_City.InsertString(0, city);
if (m_City.GetCount() > MAX_HISTORY)
m_City.DeleteString(m_City.GetCount() - 1);
}
m_City.SetCurSel(index);
}See Also C/C++ API | Categories | Notifications