Frequently Asked Component Specific Questions

Options

Display all FAQ items

Search FAQ items:


Displaying items 1 to 1 of 1, page 1 of 1

<< previous next >>

TMS FMX UI Pack
TTMSFMXGrid: A technique to check checkboxes in the grid for specific rows by using a filter

In the TMSFMXGrid, data is loaded via a CSV file and an extra column of checkboxes is added. Now, we want to check checkboxes for specific rows and instead of looping through all rows to find the matching rows and check the checkbox, we use the built-in grid filtering capability and check only the rows that remain after filtering and then remove the filter:

var
  i: integer;
begin
  TMSFMXGrid1.LoadFromCSV(''.\cars.csv'');
  TMSFMXGrid1.ColumnCount := TMSFMXGrid1.ColumnCount + 1;
  TMSFMXGrid1.AddCheckBoxColumn(TMSFMXGrid1.ColumnCount - 1);

  TMSFMXGrid1.Filter.Clear;
  TMSFMXGrid1.Filter.Add;
  TMSFMXGrid1.Filter.Items[0].Condition := ''BMW'';
  TMSFMXGrid1.Filter.Items[0].Column := 1;

  TMSFMXGrid1.ApplyFilter;

  for i := TMSFMXGrid1.FixedRows to TMSFMXGrid1.RowCount - 1 do
  begin
    TMSFMXGrid1.CheckBoxState[TMSFMXGrid1.ColumnCount - 1, TMSFMXGrid1.DisplToRealRow(i)] := true;
  end;

  TMSFMXGrid1.RemoveFilter;
end;