Set checkbox checked in stringgrid

I have an AdvStringGrid that I am loading with email information, 2 columns: display name and actual email address.  After loading, I iterate the grid and add a check box to the first column.


I am now trying to iterate again and check any rows where the email address is in an AdvMemo component, showing that it has been previously selected.  The memo content is saved on program exit and reloaded on program show.  Save / reload works ok.  There is never a match on the items though, or the check is not being applied as I expected in this code:

var Str : String;
...
  for i := 1 to emailGrid.RowCount - 1 do
    begin
      Str := trim(emailGrid.Cells[1,i]);                    // the email address column
      if AdvMemo1.Lines.Count > 0 then
        for j := 1 to AdvMemo1.Lines.Count do
          begin
             if Str = trim(AdvMemo1.Lines.Text[j]) then
               emailGrid.SetCheckBoxState(0,i,true);     // the display name column
          end;
    end;

Am I calling the wrong function to make the checkbox checked?  Is it OK to use this function in the Form1.OnShow event?

There is no information on how you add the checkbox.
These 2 lines show how a checkbox is added and the state is set:


  advstringgrid1.AddCheckBox(1,1,false,false);
  advstringgrid1.SetCheckBoxState(1,1,true);

Added check box exactly as you indicated:


   for i := 1 to emailGrid.RowCount - 1 do
    begin
      emailGrid.AddCheckBox(0,i,false,false);
    end;

Then I do the check for the match as listed in the previous code example.

OK, found my misunderstanding.  I removed the TEXT from AdvMemo1.Lines, and though I am counting from 1 in my grid (to bypass the header row), I still have to count from 0 in the AdvMemo.


This code works.

 for i := 1 to emailGrid.RowCount - 1 do
    begin
      Str := trim(emailGrid.Cells[1,i]);                    // the email address column
      if AdvMemo1.Lines.Count > 0 then
        for j := 1 to AdvMemo1.Lines.Count do
          begin
             if Str = trim(AdvMemo1.Lines[j-1]) then    <<<<< fixed
               emailGrid.SetCheckBoxState(0,i,true);     // the display name column
          end;
    end;

Thanks.  I'm glad I was using the correct code to create and set the box.