TLama

Untitled

Jul 2nd, 2014
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.90 KB | None | 0 0
  1. // load column titles with the column visibility state into the check list box
  2. var
  3.   I: Integer;
  4.   Index: Integer;
  5. begin
  6.   CheckListBox.Clear;
  7.   CheckListBox.Items.BeginUpdate;
  8.   try
  9.     for I := 0 to DBGrid.Columns.Count - 1 do
  10.     begin
  11.       Index := CheckListBox.Items.Add(DBGrid.Columns[I].Title.Caption);
  12.       CheckListBox.Checked[Index] := DBGrid.Columns[I].Visible;
  13.     end;
  14.   finally
  15.     CheckListBox.Items.EndUpdate;
  16.   end;
  17. end;
  18.  
  19. // set the columns visibility according to the check list box states; note that
  20. // the whole code shown here relies on the order of the items in the check list
  21. // box which cannot be changed (so you cannot use it for column reordering)
  22. var
  23.   I: Integer;
  24. begin
  25.   DBGrid.Columns.BeginUpdate;
  26.   try
  27.     for I := 0 to CheckListBox.Count - 1 do
  28.       DBGrid.Columns[I].Visible := CheckListBox.Checked[I];
  29.   finally
  30.     DBGrid.Columns.EndUpdate;
  31.   end;
  32. end;
Advertisement
Add Comment
Please, Sign In to add comment