Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sync (sub)Items to Columns in a TListView

Status
Not open for further replies.

hansaplast

Programmer
Dec 17, 2001
61
NL
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.
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);
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top