Карта сайта Kansoftware
НОВОСТИУСЛУГИРЕШЕНИЯКОНТАКТЫ
Разработка программного обеспечения
KANSoftWare

Обмен значениями элементов TListView

Delphi , Компоненты и Классы , TListView

Обмен значениями элементов TListView

Оформил: DeeCo
Автор: http://www.swissdelphicenter.ch

Today I want to describe how you may exchange some items in standard TListView.
For example, you have 5 items and want to swap
positions for first and third items

Problem that standard TListView component haven''t
such method and you must realize it yourself.

We remember that the standard way from old Pascal times (for numbers) is:
 procedure Swap(X, Y: Integer);
 var
   s: Integer;
 begin
   s := X;
   X := Y;
   Y := X
 end;
Something similar we can do with TListItem too.
But just to save all strings (caption+sub items) somewhere is not enough because TListItem class have a lot of other information (image indexes, pointer as Data, etc)

So correct way is to use Assign method:
 procedure ExchangeItems(lv: TListView; const i, j: Integer);
 var
   tempLI: TListItem;
 begin
   lv.Items.BeginUpdate;
   try
     tempLI := TListItem.Create(lv.Items);
     tempLI.Assign(lv.Items.Item[i]);
     lv.Items.Item[i].Assign(lv.Items.Item[j]);
     lv.Items.Item[j].Assign(tempLI);
     tempLI.Free;
   finally
     lv.Items.EndUpdate
   end;
 end;
So structure is a same as in our sample for Integer. All what we added are
BeginUpdate and EndUpdate (just allow to reduce a flickering)

So if you want to exchange items in any ListView, just call this procedure...

Статья Обмен значениями элементов TListView раздела Компоненты и Классы TListView может быть полезна для разработчиков на Delphi и FreePascal.


Комментарии и вопросы


Ваше мнение или вопрос к статье в виде простого текста (Tag <a href=... Disabled). Все комментарии модерируются, модератор оставляет за собой право удалить непонравившейся ему комментарий.

заголовок

e-mail

Ваше имя

Сообщение

Введите код




Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.



:: Главная :: TListView ::


реклама



©KANSoftWare (разработка программного обеспечения, создание программ, создание интерактивных сайтов), 2007
Top.Mail.Ru Rambler's Top100
19.03.2024 09:16:49/0.037122011184692/2