Alas, that works for ListBox, but not for ListView. For the Items property in ListBox is a TStrings that has a method Move, but the Items property of ListView is a TListItems, that has no such method.
You could try the following code (I modified dominochmiel's code). I'm not working on a computer with C++Builder right now, so you might have to make some minor adjustments.
int SelItem;
void __fastcall TForm1::ListBox1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
SelItem=ListBox1->ItemIndex;
}
void __fastcall TForm1::UpwardClick(TObject *Sender)
{
if(ListView->ItemIndex > 0)
{
AnsiString AuxValue = ListView->Items->Strings[ListView->Items->ItemIndex - 1]; // or Values instead of Strings
ListView->Items->Strings[ListView->Items->ItemIndex - 1] = ListView->Items->Strings[ListView->Items->ItemIndex];
ListView->Items->Strings[ListView->Items->ItemIndex] = AuxValue;
// or you could still use a SelItem variable, but I think that the system should select the item clicked with the mouse automaticaly
}
//---------------------------------------------------------------------------
void __fastcall TForm1:ownwardClick(TObject *Sender)
{
if(ListView->ItemIndex < ListView->Count - 1)
{
AnsiString AuxValue = ListView->Items->Strings[ListView->Items->ItemIndex + 1]; // or Values instead of Strings
ListView->Items->Strings[ListView->Items->ItemIndex + 1] = ListView->Items->Strings[ListView->Items->ItemIndex];
ListView->Items->Strings[ListView->Items->ItemIndex] = AuxValue;
}
//---------------------------------------------------------------------------
Thank you. It's indeed the manner I've used. I had to discriminate between item->Caption and item->Subitems. Also I had to provide for connected objects (item->Data). They caused undesired effects in the OnSelectItem trigger. So half a day programming for one method in a TList.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.