From Clomosy Docs

(Created page with " AddNewProListView(TComponent, xName):TClProListView; Represents the list view component that you can use to hold and present various types of items. TclListView displays a collection of items in a list optimized for fast and smooth scrolling. Apart from the standard ListView parameter properties, it has features such as background and border color rendering. We can also design the appearance of the components in the ProListView ourselves. It can be easily defined with...")
 
No edit summary
 
(15 intermediate revisions by 2 users not shown)
Line 1: Line 1:
AddNewProListView(TComponent, xName):TClProListView;
<div class="alert alert-ligth border border-3 border-primary-subtle rounded-5 p-4 shadow-sm" role="alert">
function AddNewProListView(AComponent: TCLComponent; xName: string): TClProListView;
</div>


Represents the list view component that you can use to hold and present various types of items. TclListView displays a collection of items in a list optimized for fast and smooth scrolling. Apart from the standard ListView parameter properties, it has features such as background and border color rendering. We can also design the appearance of the components in the ProListView ourselves. It can be easily defined with the following json structure parameters.<br>
<span style="color:blue"><b>AComponent</b></span> : Specifies the parent of the object to be defined.<br>


* Width
<span style="color:blue"><b>xName</b></span> : The name of the defined listview should be written.<br>
* Height
* PositionX
* PositionY
* Align
* BackgroundColor
* MarginTop
* MarginBottom
* MarginRight
* MarginLeft
* RoundHeight
* RoundWidth
* BorderColor
* BorderWidth
* ItemSpace
* ItemHeight
* ItemWidth
* ItemColumnCount
* ListType ('List' - 'Cart' - 'Fluid')


When the standard Listview definition was made, the search bar was automatically defined at the top. It is not included in ProListView. For this we need to define the "AddNewProSearchEdit" component. We will define it in the next steps. Let's first define the ProListView object.<br>
Represents the list view component that you can use to hold and present various types of items. TclListView displays a collection of items in a list optimized for fast and smooth scrolling.<br>
Besides, you use this component when you want to pull data from the database.<br>


<blockquote style="background-color:#F7F5EB">
<div class="alert alert-info" role="alert" data-bs-theme="light">
'''Var'''<br>
Refer to the [[TclListView]] page for standard listview usage.
testListview : TClProListView;
</div>
</blockquote>


Let's define ProListView in MyForm and define json structure and parameters in it. Within the json structure, "List","Cart" and "Fluid" properties can be defined as ListType of our ProListView structure.<br>
<div class="table-responsive">
If List is selected in these properties, it displays data as List.<br>
{| class="wikitable" style="border: 2px solid #c3d7e0"
If we choose the Cart property, we need to specify how many data should be added to each column ("ItemColumnCount" : 2,).<br>
! style="background-color: #c3d7e0"| Feature  !!style="background-color: #c3d7e0"| Use of !!style="background-color: #c3d7e0"| Definition
If we choose the Fluid feature, it automatically adds as much as it can fit by looking at the size of the data added to the list according to the screen size. As soon as there is an overflow, it moves to a lower line and in this way the data is listed.
|-
|TClProListView || ProListview1 : TClProListView;  || A variable belonging to the TClProListView class is created.
|-
|AddNewProListView || ProListview1 = Form1.AddNewProListView(Form1,'ProListview1'); || A new TClProListView component is added to the form.
|-
|ListType  ||ProListView1.ListType = 'horizontal'; //vertical || It is used to set the listing direction. The default value is vertical.
|-
|Properties.ItemSpace||ProListView1.Properties.ItemSpace = 10; || The spacing between listed items is defined.
|-
|clSelectedItemData ||ProListView1.clSelectedItemData(clRecord_GUID) || To access the data of the clicked item within a ListView, "clSelectedItemData" is used.
|-
|clearList ||ProListView1.clearList; || Clears all content of the ListView object.
|}
</div>


<blockquote style="background-color:#F7F5EB">
<div class="alert alert-danger" role="alert" data-bs-theme="light">
    testListview := MyForm.AddNewProListView(MyForm,'testListview');<br>
In TclListView usage, a search bar is included. However, when TclProListView is created, the search bar does not appear. For this, the [[TClProSearchEdit]] object should be used.
    clComponent.SetupComponent(testListview,'{"Height" : 150,"Align":"Client","MarginBottom":20,"MarginTop":20,"MarginRight":20,"MarginLeft":20, "ListType":"Cart","ItemHeight" : 150,"ItemWidth":150,<br>  
</div>
    "BackgroundColor":"#CEF3FE", "BorderColor":"#26DE90", "BorderWidth":2,"RoundWidth":5, "RoundHeight":5}');<br>
    MyForm.AddNewEvent(testListview,tbeOnItemClick,'onItemClicked');<br>
</blockquote>
The scrollable feature becomes active when data is added to the ProListView structure. If you do not specify the scrolling as described below, it defaults to "vertical". This means that the vertical scroll feature is turned on. If you want to make horizontal scrolling feature, you should make a definition (horizontal) as below.<br>
<blockquote style="background-color:#F7F5EB">
testListview.'''ListType''' := 'horizontal';
</blockquote>


Another feature of ProListView is that you can specify the spacing between listed variables. You can do this with the following piece of code.
<div class="row">
<blockquote style="background-color:#F7F5EB">
<div class="col-lg-6">
testListview.'''Properties.ItemSpace''' := 10;
<div  class="card d-flex flex-column justify-content-start gap-1 mb-3 h-100" style="padding: 3;">
</blockquote>
<div style="font-size: 16px;font-weight: bold;text-align:left;">
  clProSettings Properties
</div>
<div style="font-size: 14px;font-weight: normal;text-align:justify; max-width: 350px;">
<li>BackgroundColor</li>
<li>BorderColor</li>
<li>IsTransparent</li>
<li>IsFill</li>
<li>RoundHeight</li>
<li>RoundWidth</li>
<li>IsRound</li>
<li>BorderWidth</li>
<li>ItemSpace</li>
<li>ItemHeight</li>
<li>ItemWidth</li>
<li>ColCount</li>
<li>ViewType</li>
</div>
</div>
</div>
</div>
<br>
 
<div class="alert alert-warning" role="alert" data-bs-theme="light">
To learn the purpose and usage of the <b>clProSettings</b> properties, please refer to [[Pro Object Properties| the page]].
</div>
 
<h2>Example 1: Use of TclProListView</h2><br>
 
<pre>
Var 
  Form1:TclForm;
  ListView1 : TClProListView;
 
{
  Form1 = TclForm.Create(Self);
  ListView1 = Form1.AddNewProListView(Form1,'ListView1');
  ListView1.Align = AlClient;
  ListView1.Margins.Bottom = 20;
  ListView1.Margins.Top = 20;
  ListView1.Margins.Right = 20;
  ListView1.Margins.Left = 20;
  ListView1.clProSettings.ViewType = lvIcon; //(lvList, lvIcon, lvWaterFall)
  ListView1.clProSettings.ColCount = 1;
  ListView1.clProSettings.ItemHeight = 100;
  ListView1.clProSettings.ItemSpace = 10;
  ListView1.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#FFFCFF');
  ListView1.clProSettings.BorderColor = clAlphaColor.clHexToColor('#66FF7F');
  ListView1.clProSettings.BorderWidth = 2;
  ListView1.clProSettings.RoundHeight = 5;
  ListView1.clProSettings.RoundWidth = 5;
  ListView1.SetclProSettings(ListView1.clProSettings);
  Form1.Run;
}
</pre>
 
 
<h2>Example 2: Listing with JSON</h2><br>
 
In the example, a form is created and a TclProListView is added to it. The TclProListView is configured with specific properties, and a design panel (TclListViewDesignerPanel) is added. An image (TclProImage) and a label (TclProLabel) are added to the design panel. An item click event (tbeOnItemClick) is defined, which displays the selected item when triggered. Finally, JSON formatted data is loaded into the list, and the form is run.<br>
 
<pre>
Var 
  Form1:TclForm;
  ListView1 : TClProListView;
  DesignerPanel1 : TClListViewDesignerPanel;
  taskName : TclProLabel;
  taskImg : TclProImage;
 
void TaskClick;
{
  ShowMessage(' Item: ' + ListView1.clSelectedItemData(clText));
}
 
void CreateListView
{
  ListView1 = Form1.AddNewProListView(Form1,'ListView1');
  ListView1.Align = AlClient;
  ListView1.Margins.Bottom = 20;
  ListView1.Margins.Top = 20;
  ListView1.Margins.Right = 20;
  ListView1.Margins.Left = 20;
  ListView1.clProSettings.ViewType = lvIcon; //(lvList, lvIcon, lvWaterFall)
  ListView1.clProSettings.ColCount = 1;
  ListView1.clProSettings.ItemHeight = 100;
  ListView1.clProSettings.ItemSpace = 10;
  ListView1.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#FFFCFF');
  ListView1.clProSettings.BorderColor = clAlphaColor.clHexToColor('#66FF7F');
  ListView1.clProSettings.BorderWidth = 2;
  ListView1.clProSettings.RoundHeight = 5;
  ListView1.clProSettings.RoundWidth = 5;
  ListView1.SetclProSettings(ListView1.clProSettings);
}
 
void CreateDesignerPanel
{
  DesignerPanel1 = Form1.AddNewProListViewDesignerPanel(ListView1, 'DesignerPanel1');
  DesignerPanel1.Height = 100;
  DesignerPanel1.Width = 150;
  DesignerPanel1.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#B3FCE5');
  DesignerPanel1.clProSettings.BorderColor = clAlphaColor.clHexToColor('#16FF8C');
  DesignerPanel1.clProSettings.BorderWidth = 2;
  DesignerPanel1.clProSettings.RoundHeight = 20;
  DesignerPanel1.clProSettings.RoundWidth = 20;
  DesignerPanel1.SetclProSettings(DesignerPanel1.clProSettings);
 
  ListView1.SetDesignerPanel(DesignerPanel1);
}
 
void CreateData;
{
  taskImg = Form1.AddNewProImage(DesignerPanel1, 'taskImg');
  taskImg.Align = AlLeft;
  taskImg.Margins.Top = 10;
  taskImg.Margins.Bottom = 10;
  DesignerPanel1.AddPanelObject(taskImg, clImage1);
 
  taskName = Form1.AddNewProLabel(DesignerPanel1, 'taskName', 'test');
  taskName.Align = AlVertCenter;
  taskName.Height =30;
  taskName.Margins.Bottom = 10;
  taskName.Margins.Top = 10;
  taskName.Margins.Right = 10;
  taskName.Margins.Left = 10;
  taskName.clProSettings.FontColor = clAlphaColor.clHexToColor('#000000');
  taskName.clProSettings.FontSize = 20;
  DesignerPanel1.AddPanelObject(taskName, clText);
   
  Form1.AddNewEvent(ListView1,tbeOnItemClick,'TaskClick');
}
 
void AddDataToListView;
{
  ListView1.clLoadProListViewDataFromDataset(Clomosy.ClDataSetFromJSON('[
  {"taskName" : "Task 1", "taskImg" : "https://clomosy.com/learn/1Top.png"},
  {"taskName" : "Task 2", "taskImg" : "https://clomosy.com/learn/2Top.png"},
  {"taskName" : "Task 3", "taskImg" : "https://clomosy.com/learn/3Top.png"},
  {"taskName" : "Task 4", "taskImg" : "https://clomosy.com/learn/4Top.png"}
  ]'));
}
 
{
  Form1 = TclForm.Create(Self);
  CreateListView;
  CreateDesignerPanel;
  CreateData;
  AddDataToListview;
  Form1.Run;
}
</pre>
 
<b>Output:</b><br>
[[File:ProListViewExample.png|frameless|300px]]<br>


If we want to add a search bar in ProListView, we must first define the "TClProSearchEdit" variable and create a Search Edit object. Browse to the [[Clomosy_Custom_Form#AddNewProSearchEdit |AddNewProSearchEdit]] field to create this description.<br>
Before starting to design into ProListView, DesignerPanel must be added to it. And the whole design can be done within this panel. Examine the [[Clomosy_Custom_Form#AddNewProListViewDesignerPanel |AddNewProListViewDesignerPanel]] field for the DesignerPanel definition. Now let's look at a simple example of using ProListView. We will get the datas through sql database. <br>


<pre style="background-color:#E14D2A; color:white"> When performing local SQL operations, you must write your database information in the red fields in the code section, otherwise the code will not work. </pre><br>
<h2>Example 3: Listing with SQLite</h2><br>


'''Example:'''<br>
<pre>
  '''Var''' 
  var
MyForm:TclForm;
  MyForm : TclForm;
testListview : TClProListView;
  PListView1 : TClProListView;
testDesignerPanel : TClProListViewDesignerPanel;
  DesignerPanel1 : TClProListViewDesignerPanel;
productName,productPrice : TClProLabel;<br>
  productName,productPrice : TClProLabel;
procedure SetupSqlConnection;
 
begin
  void SqLiteInsertData;
     Clomosy.DBSQLServerConnect(<span style="color:red">'SQL Server','server_name','user_name','user_password','database_name',port</span>);
  {
end;<br>
     try
procedure AddDataToListview;
      Clomosy.DBSQLiteQuery.Sql.Text = '
Var
    INSERT INTO Products (productId, productName, productPrice) VALUES (1, ''Iphone 11'', 18000.00);
  foodListQuery : TClSqlQuery;
    INSERT INTO Products (productId, productName, productPrice) VALUES (2, ''Xiaomi Redmi Note 11 Pro'', 15000.50);
begin
    INSERT INTO Products (productId, productName, productPrice) VALUES (3, ''Omix X600'', 20000.75);
  foodListQuery := TClSqlQuery.Create(nil);
    INSERT INTO Products (productId, productName, productPrice) VALUES (4, ''Huawei Nova Y70'', 25000.00);
  try
    INSERT INTO Products (productId, productName, productPrice) VALUES (5, ''Samsung Galaxy S20'', 30000.25);
       foodListQuery.Connection := Clomosy.DBSQLServerConnection;
    INSERT INTO Products (productId, productName, productPrice) VALUES (6, ''Iphone 14 Pro Max'', 50000.25);';
       foodListQuery.SQL.Text := 'SELECT productId as RECORD_GUID, productName, productPrice from Products';
      Clomosy.DBSQLiteQuery.OpenOrExecute;
       foodListQuery.Open;
     
       if foodListQuery.Found then
      ShowMessage('Adding data to the table was successful!');
       begin
    except
        testListview.clLoadProListViewDataFromDataset(foodListQuery);
    ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
       end;
    }
  finally
  }
       foodListQuery.Close;
 
      foodListQuery.Free;
  void SqLiteConnectionCreateTable;
  end;
  var
  end; <br>
    TableExists: Boolean;
  procedure onItemClicked;
  {
  begin
    try
     ShowMessage('--' +testListview.clSelectedItemData(clRecord_GUID));
       Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBProduct.db3', '');
   end;
   procedure CreateDesignerPanel;
      // Check if the table exists
   begin
       Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT name FROM sqlite_master WHERE type="table" AND name="Products";';
       testDesignerPanel := MyForm.AddNewProListViewDesignerPanel(testListview,'testDesignerPanel');  
       Clomosy.DBSQLiteQuery.OpenOrExecute;
       clComponent.SetupComponent(testDesignerPanel,'{"Height":100,"Width" : 150,"BackgroundColor":"#F6EDDB","BorderColor":"#F5BCC9","BorderWidth":2,"RoundHeight":20,"RoundWidth":20}');
        
       testListview.SetDesignerPanel(testDesignerPanel);
       // Check the results
   end;<br>
      TableExists = not Clomosy.DBSQLiteQuery.Eof;
  procedure CreateListView;
        
  begin
      // Create the table if it does not exist
    testListview := MyForm.AddNewProListView(MyForm,'testListview');
      if not (TableExists)
    testListview.Properties.ItemSpace := 10;
       {
    clComponent.SetupComponent(testListview,'{"Height" : 150,"Align":"Client","MarginBottom":20,"MarginTop":20,"MarginRight":20,"MarginLeft":20, "ListType":"Cart","ItemColumnCount" : 2,"ItemHeight" : 150,"ItemWidth":150,
        Clomosy.DBSQLiteQuery.Sql.Text = 'CREATE TABLE Products(productId INTEGER NOT NULL,
    "BorderColor":"#F5BCC9", "BorderWidth":2,"RoundWidth":5, "RoundHeight":5}');
        productName TEXT NOT NULL,
    testListview.ListType := 'horizontal';
        productPrice REAL NOT NULL,
    MyForm.AddNewEvent(testListview,tbeOnItemClick,'onItemClicked');
        PRIMARY KEY (productId))';
  end;<br>
        Clomosy.DBSQLiteQuery.OpenOrExecute;
  procedure CreateProductNameAndPrice;
       
  begin
        ShowMessage('Table successfully added to the database!');
    productName := MyForm.AddNewProLabel(testDesignerPanel,'productName','test');
        SqLiteInsertData;
    clComponent.SetupComponent(productName,'{"MarginTop":10,"MarginLeft":10,"MarginRight":10,"MarginBottom":10 ,"Height":20,"Align" : "MostTop"}');
      } else
    testDesignerPanel.AddPanelObject(productName,clCaption);
      {
    productName.Properties.AutoSize := True;<br>    
        ShowMessage('The Products table already exists.');
    productPrice := MyForm.AddNewProLabel(testDesignerPanel,'productPrice','test');
      }
    clComponent.SetupComponent(productPrice,'{"MarginTop":10,"MarginLeft":10,"MarginRight":10,"MarginBottom":10 ,"Height":20,"Align" : "MostRight","Width":40}');
 
    testDesignerPanel.AddPanelObject(productPrice,clText);
     except
    productPrice.Properties.AutoSize := True;
    ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
   end;
    }
'''begin'''
  }
  MyForm := TclForm.Create(Self);
 
  CreateListView;
   void GetData;
  CreateDesignerPanel;
   var
  SetupSqlConnection;
    Qry : TClSQLiteQuery;
  CreateProductNameAndPrice;
   {
  AddDataToListview;
    try
  MyForm.Run;
       Qry = Clomosy.DBSQLiteQueryWith('SELECT productId as clRecord_GUID, productName, productPrice from Products');
'''end;'''
       Qry.OpenOrExecute;
<br>
      if (Qry.Found)
'''Output:'''<br>
      {
[[File:ProListView.png|frameless|550px]]
        PListView1.clLoadProListViewDataFromDataset(Qry);
       }
     
    except
      ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
    }
   }
 
void CreateListView;
{
  PListView1 = MyForm.AddNewProListView(MyForm,'PListView1');
  PListView1.Properties.ItemSpace = 10;
  PListView1.Align = AlClient;
  PListView1.Margins.Bottom = 20;
  PListView1.Margins.Top = 20;
  PListView1.Margins.Right = 20;
  PListView1.Margins.Left = 20;
  PListView1.clProSettings.ColCount = 2;
  PListView1.clProSettings.ItemHeight = 150;
  PListView1.clProSettings.ItemWidth = 150;
  PListView1.clProSettings.BorderColor = clAlphaColor.clHexToColor('#F5BCC9');
  PListView1.clProSettings.BorderWidth = 2;
  PListView1.clProSettings.RoundWidth = 5;
  PListView1.clProSettings.RoundHeight = 5;
  PListView1.clProSettings.ViewType = lvIcon;
  PListView1.SetclProSettings(PListView1.clProSettings);
  PListView1.ListType = 'horizontal';
}
 
 
    void CreateDesignerPanel;
{
  DesignerPanel1 = MyForm.AddNewProListViewDesignerPanel(PListView1,'DesignerPanel1');
  DesignerPanel1.Height = 100;
  DesignerPanel1.Width = 150;
  DesignerPanel1.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#F6EDDB');
  DesignerPanel1.clProSettings.BorderColor = clAlphaColor.clHexToColor('#F5BCC9');
  DesignerPanel1.clProSettings.BorderWidth = 2;
  DesignerPanel1.clProSettings.RoundWidth = 20;
  DesignerPanel1.clProSettings.RoundHeight = 20;
  DesignerPanel1.SetclProSettings(DesignerPanel1.clProSettings);
  PListView1.SetDesignerPanel(DesignerPanel1);
}
void CreateProductNameAndPrice;
{
  productName = MyForm.AddNewProLabel(DesignerPanel1,'productName','test');
  productName.Align = AlMostTop;
  productName.Height = 20;
  productName.Margins.Bottom = 10;
  productName.Margins.Top = 10;
  productName.Margins.Right = 10;
  productName.Margins.Left = 10;
  DesignerPanel1.AddPanelObject(productName,clCaption);
  productName.Properties.AutoSize = True;
    
  productPrice = MyForm.AddNewProLabel(DesignerPanel1,'productPrice','test');
  productPrice.Align = AlMostRight;
  productPrice.Width = 40;
  productPrice.Margins.Bottom = 10;
  productPrice.Margins.Top = 10;
  productPrice.Margins.Right = 10;
  productPrice.Margins.Left = 10;
  DesignerPanel1.AddPanelObject(productPrice,clText);
  productPrice.Properties.AutoSize = True;
}
 
   {
    MyForm = TclForm.Create(Self);
    CreateListView;
    CreateDesignerPanel;
    SqLiteConnectionCreateTable;
    CreateProductNameAndPrice;
    GetData;
   
    MyForm.Run;
  }
</pre>
 
<b>Output:</b><br>
[[File:ProListView.png|frameless|550px]]<br>
 
<h2> See Also </h2>
* [[Components]]
* [[Pro Object Properties]]
* [[Object Properties]]
{{#seo:|title=TClProListView in Clomosy - Clomosy Docs}}
{{#seo:|description=Explore TClProListView in Clomosy! A guide to implementing powerful list views for dynamic data display in mobile applications.}}

Latest revision as of 08:37, 16 April 2025

AComponent : Specifies the parent of the object to be defined.

xName : The name of the defined listview should be written.

Represents the list view component that you can use to hold and present various types of items. TclListView displays a collection of items in a list optimized for fast and smooth scrolling.
Besides, you use this component when you want to pull data from the database.

Feature Use of Definition
TClProListView ProListview1 : TClProListView; A variable belonging to the TClProListView class is created.
AddNewProListView ProListview1 = Form1.AddNewProListView(Form1,'ProListview1'); A new TClProListView component is added to the form.
ListType ProListView1.ListType = 'horizontal'; //vertical It is used to set the listing direction. The default value is vertical.
Properties.ItemSpace ProListView1.Properties.ItemSpace = 10; The spacing between listed items is defined.
clSelectedItemData ProListView1.clSelectedItemData(clRecord_GUID) To access the data of the clicked item within a ListView, "clSelectedItemData" is used.
clearList ProListView1.clearList; Clears all content of the ListView object.

clProSettings Properties

  • BackgroundColor
  • BorderColor
  • IsTransparent
  • IsFill
  • RoundHeight
  • RoundWidth
  • IsRound
  • BorderWidth
  • ItemSpace
  • ItemHeight
  • ItemWidth
  • ColCount
  • ViewType

  • Example 1: Use of TclProListView


    Var   
      Form1:TclForm;
      ListView1 : TClProListView;
      
    {
      Form1 = TclForm.Create(Self);
      ListView1 = Form1.AddNewProListView(Form1,'ListView1');
      ListView1.Align = AlClient;
      ListView1.Margins.Bottom = 20;
      ListView1.Margins.Top = 20;
      ListView1.Margins.Right = 20;
      ListView1.Margins.Left = 20;
      ListView1.clProSettings.ViewType = lvIcon; //(lvList, lvIcon, lvWaterFall)
      ListView1.clProSettings.ColCount = 1;
      ListView1.clProSettings.ItemHeight = 100;
      ListView1.clProSettings.ItemSpace = 10;
      ListView1.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#FFFCFF');
      ListView1.clProSettings.BorderColor = clAlphaColor.clHexToColor('#66FF7F');
      ListView1.clProSettings.BorderWidth = 2;
      ListView1.clProSettings.RoundHeight = 5;
      ListView1.clProSettings.RoundWidth = 5;
      ListView1.SetclProSettings(ListView1.clProSettings);
      Form1.Run;
    }
    


    Example 2: Listing with JSON


    In the example, a form is created and a TclProListView is added to it. The TclProListView is configured with specific properties, and a design panel (TclListViewDesignerPanel) is added. An image (TclProImage) and a label (TclProLabel) are added to the design panel. An item click event (tbeOnItemClick) is defined, which displays the selected item when triggered. Finally, JSON formatted data is loaded into the list, and the form is run.

    Var   
      Form1:TclForm;
      ListView1 : TClProListView;
      DesignerPanel1 : TClListViewDesignerPanel;
      taskName : TclProLabel;
      taskImg : TclProImage;
      
    void TaskClick;
    {
      ShowMessage(' Item: ' + ListView1.clSelectedItemData(clText));
    }
    
    void CreateListView
    {
      ListView1 = Form1.AddNewProListView(Form1,'ListView1');
      ListView1.Align = AlClient;
      ListView1.Margins.Bottom = 20;
      ListView1.Margins.Top = 20;
      ListView1.Margins.Right = 20;
      ListView1.Margins.Left = 20;
      ListView1.clProSettings.ViewType = lvIcon; //(lvList, lvIcon, lvWaterFall)
      ListView1.clProSettings.ColCount = 1;
      ListView1.clProSettings.ItemHeight = 100;
      ListView1.clProSettings.ItemSpace = 10;
      ListView1.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#FFFCFF');
      ListView1.clProSettings.BorderColor = clAlphaColor.clHexToColor('#66FF7F');
      ListView1.clProSettings.BorderWidth = 2;
      ListView1.clProSettings.RoundHeight = 5;
      ListView1.clProSettings.RoundWidth = 5;
      ListView1.SetclProSettings(ListView1.clProSettings);
    }
    
    void CreateDesignerPanel
    {
      DesignerPanel1 = Form1.AddNewProListViewDesignerPanel(ListView1, 'DesignerPanel1');
      DesignerPanel1.Height = 100;
      DesignerPanel1.Width = 150;
      DesignerPanel1.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#B3FCE5');
      DesignerPanel1.clProSettings.BorderColor = clAlphaColor.clHexToColor('#16FF8C');
      DesignerPanel1.clProSettings.BorderWidth = 2;
      DesignerPanel1.clProSettings.RoundHeight = 20;
      DesignerPanel1.clProSettings.RoundWidth = 20;
      DesignerPanel1.SetclProSettings(DesignerPanel1.clProSettings);
      
      ListView1.SetDesignerPanel(DesignerPanel1);
    }
    
    void CreateData;
    {
      taskImg = Form1.AddNewProImage(DesignerPanel1, 'taskImg');
      taskImg.Align = AlLeft;
      taskImg.Margins.Top = 10;
      taskImg.Margins.Bottom = 10;
      DesignerPanel1.AddPanelObject(taskImg, clImage1);
    
      taskName = Form1.AddNewProLabel(DesignerPanel1, 'taskName', 'test');
      taskName.Align = AlVertCenter;
      taskName.Height =30;
      taskName.Margins.Bottom = 10;
      taskName.Margins.Top = 10;
      taskName.Margins.Right = 10;
      taskName.Margins.Left = 10;
      taskName.clProSettings.FontColor = clAlphaColor.clHexToColor('#000000');
      taskName.clProSettings.FontSize = 20;
      DesignerPanel1.AddPanelObject(taskName, clText);
        
      Form1.AddNewEvent(ListView1,tbeOnItemClick,'TaskClick');
    }
    
    void AddDataToListView;
    {
      ListView1.clLoadProListViewDataFromDataset(Clomosy.ClDataSetFromJSON('[
      {"taskName" : "Task 1", "taskImg" : "https://clomosy.com/learn/1Top.png"},
      {"taskName" : "Task 2", "taskImg" : "https://clomosy.com/learn/2Top.png"},
      {"taskName" : "Task 3", "taskImg" : "https://clomosy.com/learn/3Top.png"},
      {"taskName" : "Task 4", "taskImg" : "https://clomosy.com/learn/4Top.png"}
      ]'));
    }
    
    {
      Form1 = TclForm.Create(Self);
      CreateListView;
      CreateDesignerPanel;
      CreateData;
      AddDataToListview;
      Form1.Run;
    }
    

    Output:
    ProListViewExample.png


    Example 3: Listing with SQLite


     var
      MyForm : TclForm;
      PListView1 : TClProListView;
      DesignerPanel1 : TClProListViewDesignerPanel;
      productName,productPrice : TClProLabel;
      
      void SqLiteInsertData;
      {
        try
          Clomosy.DBSQLiteQuery.Sql.Text = '
        INSERT INTO Products (productId, productName, productPrice) VALUES (1, ''Iphone 11'', 18000.00);
        INSERT INTO Products (productId, productName, productPrice) VALUES (2, ''Xiaomi Redmi Note 11 Pro'', 15000.50);
        INSERT INTO Products (productId, productName, productPrice) VALUES (3, ''Omix X600'', 20000.75);
        INSERT INTO Products (productId, productName, productPrice) VALUES (4, ''Huawei Nova Y70'', 25000.00);
        INSERT INTO Products (productId, productName, productPrice) VALUES (5, ''Samsung Galaxy S20'', 30000.25);
        INSERT INTO Products (productId, productName, productPrice) VALUES (6, ''Iphone 14 Pro Max'', 50000.25);';
          Clomosy.DBSQLiteQuery.OpenOrExecute;
          
          ShowMessage('Adding data to the table was successful!');
        except
         ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
        }
      }
      
      void SqLiteConnectionCreateTable;
      var
        TableExists: Boolean;
      {
        try
          Clomosy.DBSQLiteConnect(Clomosy.AppFilesPath + 'DBProduct.db3', '');
     
          // Check if the table exists
          Clomosy.DBSQLiteQuery.Sql.Text = 'SELECT name FROM sqlite_master WHERE type="table" AND name="Products";';
          Clomosy.DBSQLiteQuery.OpenOrExecute;
          
          // Check the results
          TableExists = not Clomosy.DBSQLiteQuery.Eof;
          
          // Create the table if it does not exist
          if not (TableExists)
          {
            Clomosy.DBSQLiteQuery.Sql.Text = 'CREATE TABLE Products(productId INTEGER NOT NULL,
            productName TEXT NOT NULL,
            productPrice REAL NOT NULL,
            PRIMARY KEY (productId))';
            Clomosy.DBSQLiteQuery.OpenOrExecute;
            
            ShowMessage('Table successfully added to the database!');
            SqLiteInsertData;
          } else
          {
            ShowMessage('The Products table already exists.');
          }
    
        except
         ShowMessage('Exception Class: '+LastExceptionClassName+' Exception Message: '+LastExceptionMessage);
        }
      }
      
      void GetData;
      var
        Qry : TClSQLiteQuery;
      {
        try
          Qry = Clomosy.DBSQLiteQueryWith('SELECT productId as clRecord_GUID, productName, productPrice from Products');
          Qry.OpenOrExecute;
          if (Qry.Found)
          {
            PListView1.clLoadProListViewDataFromDataset(Qry);
          }
          
        except
          ShowMessage('Exception class: '+LastExceptionClassName+' Exception Message: ' +LastExceptionMessage);
        } 
      }
    
     void CreateListView;
     {
       PListView1 = MyForm.AddNewProListView(MyForm,'PListView1');
       PListView1.Properties.ItemSpace = 10;
       PListView1.Align = AlClient;
       PListView1.Margins.Bottom = 20;
       PListView1.Margins.Top = 20;
       PListView1.Margins.Right = 20;
       PListView1.Margins.Left = 20;
       PListView1.clProSettings.ColCount = 2;
       PListView1.clProSettings.ItemHeight = 150;
       PListView1.clProSettings.ItemWidth = 150;
       PListView1.clProSettings.BorderColor = clAlphaColor.clHexToColor('#F5BCC9');
       PListView1.clProSettings.BorderWidth = 2;
       PListView1.clProSettings.RoundWidth = 5;
       PListView1.clProSettings.RoundHeight = 5;
       PListView1.clProSettings.ViewType = lvIcon;
       PListView1.SetclProSettings(PListView1.clProSettings);
       PListView1.ListType = 'horizontal';
     }
    
      
        void CreateDesignerPanel;
     {
       DesignerPanel1 = MyForm.AddNewProListViewDesignerPanel(PListView1,'DesignerPanel1');
       DesignerPanel1.Height = 100;
       DesignerPanel1.Width = 150;
       DesignerPanel1.clProSettings.BackgroundColor = clAlphaColor.clHexToColor('#F6EDDB');
       DesignerPanel1.clProSettings.BorderColor = clAlphaColor.clHexToColor('#F5BCC9');
       DesignerPanel1.clProSettings.BorderWidth = 2;
       DesignerPanel1.clProSettings.RoundWidth = 20;
       DesignerPanel1.clProSettings.RoundHeight = 20;
       DesignerPanel1.SetclProSettings(DesignerPanel1.clProSettings);
       PListView1.SetDesignerPanel(DesignerPanel1);
     }
     void CreateProductNameAndPrice;
     {
       productName = MyForm.AddNewProLabel(DesignerPanel1,'productName','test');
       productName.Align = AlMostTop;
       productName.Height = 20;
       productName.Margins.Bottom = 10;
       productName.Margins.Top = 10;
       productName.Margins.Right = 10;
       productName.Margins.Left = 10;
       DesignerPanel1.AddPanelObject(productName,clCaption);
       productName.Properties.AutoSize = True;
       
       productPrice = MyForm.AddNewProLabel(DesignerPanel1,'productPrice','test');
       productPrice.Align = AlMostRight;
       productPrice.Width = 40;
       productPrice.Margins.Bottom = 10;
       productPrice.Margins.Top = 10;
       productPrice.Margins.Right = 10;
       productPrice.Margins.Left = 10;
       DesignerPanel1.AddPanelObject(productPrice,clText);
       productPrice.Properties.AutoSize = True;
     }
    
      {
        MyForm = TclForm.Create(Self);
        CreateListView;
        CreateDesignerPanel;
        SqLiteConnectionCreateTable;
        CreateProductNameAndPrice;
        GetData;
        
        MyForm.Run;
      }
    

    Output:
    ProListView.png

    See Also