Grid shows Hidden Columns?

Hi,

I have a formula containing 4 Checkboxes and a AdvStringGrid with 39 columns. Clicking the Checkboxes hides or unhides some columns.

If I check more than two Checkboxes the Grid show a wrong amount of columns (for example ...,36, 37, 38, '', 35, 36, 37) and a Access-Violation Error is displaying after closing the form.

Heres my example code:


procedure TForm1.CheckBoxClick(Sender: TObject);
begin
    resetGrid;
end;

procedure TForm1.resetGrid;
var i: integer;
begin
    with AdvStringGrid1 do
    begin
        ColCount := 39;
    
        // just numbering then Column header
        for I := 0 to 38 do cells[i, 0] := IntToStr(i);          

        UnHideColumnsAll;
        if CheckBox1.Checked then HideColumns(4,12);
        if CheckBox2.Checked then HideColumns(13,16);
        if CheckBox3.Checked then HideColumns(17,26);
        if CheckBox4.Checked then HideColumns(27,32);
    end;     
end;

Can you reproduce it?

Please change your code to:


procedure TForm1.CheckBox1Click(Sender: TObject);
var
  i: integer;
begin
  with AdvStringGrid1 do
  begin
    UnHideColumnsAll;
    ColCount := 39;

    // just numbering then Column header
     for I := 0 to 38 do cells[i, 0] := IntToStr(i);

    if CheckBox1.Checked then HideColumns(4,12);
    if CheckBox2.Checked then HideColumns(13,16);
    if CheckBox3.Checked then HideColumns(17,26);
    if CheckBox4.Checked then HideColumns(27,32);
  end;
end;