Недавно добавленные исходники

•  TDictionary Custom Sort  3 227

•  Fast Watermark Sources  2 993

•  3D Designer  4 752

•  Sik Screen Capture  3 260

•  Patch Maker  3 469

•  Айболит (remote control)  3 530

•  ListBox Drag & Drop  2 907

•  Доска для игры Реверси  80 800

•  Графические эффекты  3 844

•  Рисование по маске  3 172

•  Перетаскивание изображений  2 544

•  Canvas Drawing  2 674

•  Рисование Луны  2 501

•  Поворот изображения  2 094

•  Рисование стержней  2 121

•  Paint on Shape  1 526

•  Генератор кроссвордов  2 183

•  Головоломка Paletto  1 731

•  Теорема Монжа об окружностях  2 159

•  Пазл Numbrix  1 649

•  Заборы и коммивояжеры  2 017

•  Игра HIP  1 262

•  Игра Go (Го)  1 201

•  Симулятор лифта  1 426

•  Программа укладки плитки  1 179

•  Генератор лабиринта  1 512

•  Проверка числового ввода  1 297

•  HEX View  1 466

•  Физический маятник  1 322

•  Задача коммивояжера  1 357

 
скрыть


Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

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



Оформил: DeeCo

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...




Похожие по теме исходники

Clipboard (буфер обмена)




Copyright © 2004-2024 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте