仅显示通过SQL在DBGrid的TCheckListBox中选择的字段

时间:2018-10-01 13:41:34

标签: sql database delphi ms-access tadoquery

所以我有一个TDBGrid,它通过SQL显示查询的内容。 我只需要显示在TCheckListBox中选择的字段/列。我该怎么解决这个问题?

In this case the 'Lengte' field should not be included'

2 个答案:

答案 0 :(得分:1)

这些列链接回到数据源,因此您可以遍历它们,直到找到所需的列为止。

<p> </p>

答案 1 :(得分:0)

让它开始工作!

var
  i, j: integer;
  arrColsToHide: array[0..11] of string;
begin
// resets all columns to VISIBLE and clears array
  for i := 0 to 11 do
    begin
      arrColsToHide[i]:= '';
      dbGridExport.Columns[i+1].Visible:= true;
    end;
// if item is not checked, add it to the array
  for i := 0 to 11 do
    if not(clbFieldsToExport.Checked[i])
      then arrColsToHide[i]:= clbFieldsToExport.Items.Strings[i];
// compares value of array to fieldname, and hide if same
  for j := 0 to 11 do
    begin
      for i := 1 to dbGridExport.Columns.Count-1 do
        if dbGridExport.Columns[i].FieldName = arrColsToHide[j]
          then dbGridExport.Columns[i].Visible := false;
    end;
end;
相关问题