hansaplast
Programmer
A long time ago I needed a component which was capable of adding columns and items in a listview. Then Lord Borland presented me the TListView component with which I could add columns and items as much as I liked. I could even add subitems and the world became a beautiful place.
I then got the absurd idea of assigning the items and subitems to the columns, so that when a column was moved or added the items would move along with it.
This however seemed to be an impossible task. When columns are added or moved (sub) item positions become garbled. And the world became hell.
I found out that column indexes are in sync with (sub)item positions except for the last one added.
So if you want to fiddle around with column positions just add a dummy column, fiddle your index and remove de dummy column.
Do the same thing when adding columns.
I know the solution is a workaround but so far no one has given me a proper one.
Best regards,
Hansa
I then got the absurd idea of assigning the items and subitems to the columns, so that when a column was moved or added the items would move along with it.
This however seemed to be an impossible task. When columns are added or moved (sub) item positions become garbled. And the world became hell.
I found out that column indexes are in sync with (sub)item positions except for the last one added.
So if you want to fiddle around with column positions just add a dummy column, fiddle your index and remove de dummy column.
Code:
int ItemYouWantToMove = ListView1->Columns->Count;
int m_shift = 2;
// Add this dummy column to get the (item and subitem) indexes straight
TListColumn * dCol = ListView1->Columns->Add();
// Fiddle your Index
ListView1->Columns->Items[ItemYouWantToMove]->Index += m_shift;
// Delete the dummy column
ListView1->Columns->Delete(dCol->Index);
I know the solution is a workaround but so far no one has given me a proper one.
Best regards,
Hansa