XE ListBox for Telescopic effects

Source: Internet
Author: User

Function: To achieve the date of compression, the initialization of the item is all years, click the year to expand the month, click the Month to expand the day, then click on the contraction.

Idea: Actually the first is to display all the item, just to assign the item.height of the month day to 0,

Record index of item for each line, including year, month, day,

Find the item of the year, when clicked, show the item of the month, assign Month.height can, other same.

The next step is to process the boundary values.

Unit listbox_test;interfaceuses system.sysutils, System.types, System.uitypes, system.classes, System.Variants, FMX. Types, FMX. Graphics, FMX. Controls, FMX. Forms, FMX. Dialogs, Fmx.stdctrls, Strutils, FMX. Layouts, FMX. ListBox, FMX. Memo, FMX. Controls.presentation, FMX.    Scrollbox;type tlistboxfortest = Class (Tform) Listbox1:tlistbox;    Layout1:tlayout;    Memo1:tmemo;    Procedure Formcreate (Sender:tobject);      Procedure Listbox1itemclick (const sender:tcustomlistbox;  Const Item:tlistboxitem);  Private {Private declarations} public {public declarations} End;var listboxfortest:tlistboxfortest;  year:array[0..2] of string = (' 2015 ', ' 2014 ', ' 2013 ');  month:array[0..3] of Integer = (1, 2, 3, 4);  day:array[0..4] of Integer = (10, 11, 12, 13, 14);  Yearindex:array of Integer;    Monthindex:array of Array of integers;  two-dimensional expandyear:integer; expandmonth:integer;implementation{$R *.fmx}procedure tlistboxfortest.formcreate (sender:toBject);    var Yitem:tlistboxitem;    Mitem:tlistboxitem;    Ditem:tlistboxitem;    Iyear:integer;    Imonth:integer;  Iday:integer;begin//Set default value Expandyear: =-1;  Expandmonth: =-1;  Initialization length SetLength (yearindex, Length (year));   SetLength (Monthindex, Length (year), Length (Month));    With ListBox1 do begin beginupdate;      For iyear: = 0 to Length (year)-1 does begin yitem: = Tlistboxitem.create (nil);      Yitem.parent: = ListBox1;      Yitem.name: = ' year ' + year[iyear];      Yitem.text: = ' year ' + year[iyear];      Yitem.height: = 40; Yearindex[iyear]: = ListBox1.        items.count-1;          For imonth: = 0 to Length (Month)-1 does begin mitem: = Tlistboxitem.create (nil);          Mitem.parent: = ListBox1; Mitem.name: = ' month ' + month[imonth].          ToString; Mitem.text: = ' month ' + month[imonth].          ToString;          Mitem.height: = 0; Monthindex[iyear,imonth]: = ListBox1.          items.count-1; For iday: = 0 to Length (day)-1 DO begin Ditem: = Tlistboxitem.create (nil);            Ditem.parent: = ListBox1; Ditem.name: = ' Day ' + Day[iday].            ToString; Ditem.text: = ' Day ' + Day[iday].            ToString;          Ditem.height: = 0;      End    End    End  endupdate;  End For iyear: = 0 to Length (year)-1 does begin self. MEMO1.LINES.ADD (' year ' + year[iyear] + ': ' + yearindex[iyear].    ToString); For imonth: = 0 to Length (Month)-1 does begin self. MEMO1.LINES.ADD (' month ' + month[imonth]. ToString + ': ' + monthindex[iyear,imonth].    ToString);  End  End;end;procedure Tlistboxfortest.listbox1itemclick (const sender:tcustomlistbox;  const item:tlistboxitem); var seleteditemname:string;  Seleteditemindex:integer;  Endindex:integer;  Finditemindex:integer;  Subitemindex:integer;  Temp:integer; Temp_1:integer;begin seleteditemname: = Listbox1.listitems[listbox1.itemindex].  Name; Selected item Name Seleteditemindex: = Listbox1.listiteMs[listbox1.itemindex]. Index;    The selected item index if LEFTSTR (Seleteditemname, 4) = ' year ' then begin for finditemindex:=0 to Length (yearindex)-1 does begin  If yearindex[finditemindex] = Seleteditemindex then//year index break;  End If Listbox1.listitems[seleteditemindex + 1].  Height = expandyear: = Finditemindex Else Expandyear: =-1; If Expandyear <>-1 THEN BEGIN if Finditemindex = Length (yearindex)-1 then EndIndex: = Listbox1.ite Ms.      Count-1 else EndIndex: = Yearindex[finditemindex + 1]-1;        With ListBox1 do begin beginupdate; For Subitemindex: = Seleteditemindex + 1 to EndIndex do begin listbox1.listitems[subitemindex].          Height: = 0; Listbox1.listitems[subitemindex].        Visible: = false;        End      endupdate;      End    Expandyear: =-1;     End ELSE BEGIN Temp: = Length (Monthindex[finditemindex]);       The number of the selected year and month index with ListBox1 do begin beginupdate; For Subitemindex: = 0 to Temp-1 do begin temp_1: = Monthindex[finditemindex,subitemindex]; Traverse the selected item Next level (month) for each itemindex listbox1.listitems[temp_1].            Height: = 30; Listbox1.listitems[temp_1].          Visible: = true;            End                  Expandyear: = Finditemindex;        Unfold the itemindex endupdate of the year;     End  End  End For temp: = 0 to Length (year)-1 does for temp_1: = 0 to Length (Month)-1 do if Seleteditemindex = monthindex[                  Temp,temp_1] THEN BEGIN expandyear: = temp;        Expanded year itemindex break;  End if (leftstr (seleteditemname,5) = ' month ') and (Expandyear <>-1) THEN BEGIN temp: = Length (monthindex[expandyear    ]); For Finditemindex: = 0 to Temp-1 does begin if monthindex[expandyear, finditemindex] = Seleteditemindex then/    /unfolded month itemindex break;    End If Listbox1.listitems[seleteditemindex + 1]. Height = Expandmonth:= Finditemindex Else Expandmonth: =-1;            If Finditemindex <> temp-1 then//processing boundary value EndIndex: = monthindex[expandyear, Finditemindex + 1]-1 Last index of day of the month else begin if Expandyear <> Length (year) – 1 then EndIndex: = Yearindex[expandye    AR + 1]-1 else EndIndex: = listbox1.items.count-1;    End      The index of the day is the month Click (subitemindex) mitemindex+1-the index between the next (EndIndex) Mitemindex + 1 with the ListBox1 do begin beginupdate;        For subitemindex: = Monthindex[expandyear, Finditemindex] + 1 to EndIndex do//The next level of the month from the first to the last traversal show begin If Expandmonth =-1 THEN BEGIN Listbox1.listitems[subitemindex].            Height: = 30; Listbox1.listitems[subitemindex].          Visible: = true; End ELSE begin Listbox1.listitems[subitemindex].            Height: = 0; Listbox1.listitems[subitemindex].          Visible: = false;      End      End    If Expandmonth =-1 Then    Expandmonth: = Finditemindex Else Expandmonth: =-1;    endupdate;  End End;end;end.

XE ListBox for Telescopic effects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.