Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-06

DBGrid columns visible/not visible

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bob K.

I'm trying to reuse a single DBGrid for multiple tables. I have a list box, and when an entry is selected all columns are made invisible, and only the selected table entries are made visible. It works fine the first time the entry is clicked. The second time the entry is clicked all the fields show up.

Example in the following code:

Chemical is clicked in the list box. The CHEMICALID field is invisible and the CHEMICAL field is visible with the title caption Chemical. I click on another entry and nothing happens (which is fine at the moment). If I click Chemical again, both the CHEMICALID and CHEMICAL field are visible, and the CHEMICAL title caption is no longer Chemical, but CHEMICAL.

      Code:
      procedure TFormMain.ListBoxTablesClick(Sender: TObject);
      var
         i: integer;
         index: integer;
      begin
        index:=ListBoxTables.ItemIndex;
        if index<0 then exit;
        // make all columns not visible
        for i:=0 to DBGridGeneric.Columns.Count-1 do
          DBGridGeneric.Columns[i].Visible:=False;
        //DBGridGeneric.Clear;
        // chemical table
        if ListBoxTables.Items[index]='Chemical' then
          begin
            ZTableGeneric.TableName:='CHEMICAL';
            ZTableGeneric.SortedFields:='CHEMICAL';
            ZTableGeneric.Active:=True;
            with DBGridGeneric do
              begin
                for i:=0 to Columns.Count-1 do
                  if Columns[i].Title.Caption='CHEMICALID' then
                    Columns[i].Visible:=False;
                  if Columns[i].Title.Caption='CHEMICAL' then
                    begin
                      Columns[i].Title.Caption:='Chemical';
                      Columns[i].Visible:=True;
                    end;
                 showmessage(booltostr(columns[0].Visible));
              end;
          end; // chemical table
      {
        // measure units table
        if ListBoxTables.Items[index]='Measure Units' then
        showmessage('yup');
          begin
            with DBGridGeneric do
              begin
                ZTableGeneric.TableName:='MEASURE UNITS';
                ZTableGeneric.SortedFields:='UNITS';
                for i:=0 to Columns.Count-1 do
                  if Columns[i].Title.Caption='UNITS' then
                    begin
                      Columns[i].Title.Caption:='Unit';
                      Columns[i].Visible:=True;
                    end;
               end;
           end; // measure units
       }
      end;

What am I doing wrong?

bob k.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20080609/8a1dc409/attachment.html

Reply by email

Jesus Reyes
to Bob K.

--- "Bob K." escribi?:

Show quoted text 14 lines
ZTableGeneric.TableName:='CHEMICAL'; ZTableGeneric.SortedFields:='CHEMICAL'; ZTableGeneric.Active:=True; with DBGridGeneric do begin for i:=0 to Columns.Count-1 do if Columns[i].Title.Caption='CHEMICALID' then Columns[i].Visible:=False; [1] if Columns[i].Title.Caption='CHEMICAL' then begin Columns[i].Title.Caption:='Chemical'; Columns[i].Visible:=True; bob k.> _______________________________________________

Setting dataset active to true when it's true doesn't make it retrieve field set again, testing for uppercase CHEMICAL the first time it's ok but as column's caption is changed to a different case next time the test will fail, try in [1]: if
comparetext(Columns[i].Title.Caption,'CHEMICAL')=0 then

Jesus Reyes A.

____________________________________________________________________________________ Yahoo! Deportes Beta
?No te pierdas lo ?ltimo sobre el torneo clausura 2008! Ent?rate aqu? http://deportes.yahoo.com

Reply by email