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.
_______________________________________________
Lazarus mailing list
[email protected]
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to