Smart Mobile Studio
  • News
  • Forums
  • Download
  • Store
  • Showcases
    • Featured demos
    • The Smart Contest 2013, Round 1 – Graphics
  • Documentation
    • Get the book
    • System requirements
    • Prerequisites
    • Getting started
      • Introduction
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • Themes and styles
    • Project types
      • Visual project
      • Game project
      • Console project
    • Layout manager
    • Networking
      • TW3HttpRequest
      • TW3JSONP
      • Loading files
  • About

Working with the grid component (part 2)

Posted on 13.02.2014 by Bojan Nikolic Posted in Developers log, Documentation 1 Comment

In this article we will further explain every part of working with W3Grid. Make sure to read Part 1 before reading this article.

1. Working with rows

Beside the AddRow method, rows may be added by using the InsertRow method. With this method row may be added at any position, not only at the end.

Example:

W3Grid1.InsertRow(5);

InsertRow method also updates the LastAddedRow property.

To delete a specified row call:

DeleteRow(RowIndex);

Before deleting a row it is recommend to check if row’s index is valid:

if W3Grid1.RowExist(IndexToDelete) then
  W3Grid1.DeleteRow(IndexToDelete);

To delete all rows in a grid call method ClearRows. This method delete only rows, column structure will remain intact.

Every TW3Row is a standalone object (TW3CustomControl descendant) and it may be accessed via the Row array property. Handy (read-only) property RowCount may be used to iterate trough all rows.

Example:

procedure TForm1.W3Button1Click(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to MyGrid.RowCount - 1 do
    if i mod 2 = 0 then
      MyGrid.Row[i].Color := clCream;
end;

In this example we are painting every second row in different color.

2. Working with cells

As mentioned in the first article, a cell may be accessed via the Cell array property.

In W3Grid, every cell is a TW3CustomControl descendant. You may therefore typecast the Cell property to TW3CustomControl to access its properties and methods.

Example:

(MyGrid.Cell[0, 0] as TW3CustomControl).Color := clYellow;
(MyGrid.Cell[0, 0] as TW3CustomControl).Font.Weight := 'bold';
(MyGrid.Cell[0, 0] as TW3CustomControl).Font.Size := 16;

Result:

Windows_7_x64-2

By using TW3CustomControl methods you may also adjust child controls within a cell (e.g. progress bar inside a TW3ProgressColumn, toggle switch inside a TW3ToggleSwitchColumn and similar).

3. Working with Columns

Beside properties and methods, some column types offer events which can be handled in your code. For example, you may want to respond when user clicks on a button inside a TW3ButtonColumn, or toggle a switch inside a TW3ToggleSwitchColumn.

At the moment, Column event handlers must be created manually.

procedure TForm1.InitializeForm;
begin
  inherited;
  MyButtonColumn.OnButtonClick := W3ButtonColumnButtonClick; // link to handler
end;

procedure TForm1.W3ButtonColumnButtonClick(Sender: TObject)
begin
  // event handler - your code here
end;

Design-time editor is planed for future releases.

Grid tutorial
« Working with the grid component (part 1)
Working with the grid component (part 3) »

One thought on “Working with the grid component (part 2)”

  1. warleyalex says:
    23.02.2014 at 21:45

    Hi,
    I created an Android application with Smart Mobile Studio with remote pagination and filtering.
    I would like to know if I can create using pure Smart solution?

    See at:
    [url]http://youtu.be/IVARdw473mc[/url]

Comments are closed.

Pages

  • About
  • Feature Matrix
  • Forums
  • News
  • Release History
  • Download
  • Showcases
    • The Smart Contest 2013, Round 1 – Graphics
  • Store
  • Documentation
    • Creating your own controls
    • Debugging, exceptions and error handling
    • Differences between Delphi and Smart
    • Get the book
    • Getting started
      • Introduction
      • Local storage, session storage and global storage
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • pmSmart Box Model
      • Themes and styles
    • Layout manager
    • Networking
      • Loading files
      • TW3HttpRequest
      • TW3JSONP
    • Prerequisites
    • Real data, talking to sqLite
    • System requirements
    • Project types
      • Visual project
      • Game project
      • Console project

Archives

  • December 2019
  • December 2018
  • November 2018
  • July 2018
  • June 2018
  • February 2018
  • September 2017
  • April 2017
  • November 2016
  • October 2016
  • September 2016
  • April 2016
  • March 2016
  • January 2016
  • October 2015
  • September 2015
  • July 2015
  • April 2015
  • January 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • November 2011
  • October 2011
  • September 2011

Categories

  • Announcements (25)
  • Developers log (119)
  • Documentation (26)
  • News (104)
  • News and articles (16)

WordPress

  • Register
  • Log in
  • WordPress

Subscribe

  • Entries (RSS)
  • Comments (RSS)
© Optimale Systemer AS