在StringGrid有3列,20行
--  代码    姓名     是否结婚
    001     张三        0
    002     里司        1
    003     王五1       1
    004     王五2       0
    005     王五3       0
    006     王五4       0
    007     王五5       1   .....
现在的问题是:程序一运行,光标定位到stringgrid中的'是否结婚'的值是0的行,而且在进行上、下
              键移动时,光标跳到还是0的行,即,'是否结婚'是1 的行不选中,跳过去。

解决方案 »

  1.   

    ...procedure TForm1.FormCreate(Sender: TObject);
    begin
      Form1.KeyPreview := True;
      StringGrid1.Cells[1,0] := '代码';
      StringGrid1.Cells[2,0] := '姓名';
      StringGrid1.Cells[3,0] := '是否结婚';
      StringGrid1.Cells[1,1] := '001';
      StringGrid1.Cells[2,1] := '张三';
      StringGrid1.Cells[3,1] := '0';
      StringGrid1.Cells[1,2] := '002';
      StringGrid1.Cells[2,2] := '里司';
      StringGrid1.Cells[3,2] := '1';
      StringGrid1.Cells[1,3] := '003';
      StringGrid1.Cells[2,3] := '王五1';
      StringGrid1.Cells[3,3] := '1';
      StringGrid1.Cells[1,4] := '004';
      StringGrid1.Cells[2,4] := '王五2';
      StringGrid1.Cells[3,4] := '0';
      StringGrid1.Col := 3;
      StringGrid1.Row := 1;
    end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
      var
       i:integer;
    begin
      if Ord(key) = 40 then
      begin
        for i := (StringGrid1.Row + 1) to 4 do
          if StringGrid1.Cells[3,i] = '0' then
          begin
            StringGrid1.Row := i;
            StringGrid1.Col := 3;
            Exit;
          end;
      end;end;
    以上代码调试通过!
      

  2.   

    if Ord(key) = 38 then
    for i := 4 downto (StringGrid1.Row + 1) do
    begin
      //
    end;
      

  3.   

    ...-_-#只是思路拉,大哥!//向上
    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Form1.KeyPreview := True;
      StringGrid1.Cells[1,0] := '代码';
      StringGrid1.Cells[2,0] := '姓名';
      StringGrid1.Cells[3,0] := '是否结婚';
      StringGrid1.Cells[1,1] := '001';
      StringGrid1.Cells[2,1] := '张三';
      StringGrid1.Cells[3,1] := '0';
      StringGrid1.Cells[1,2] := '002';
      StringGrid1.Cells[2,2] := '里司';
      StringGrid1.Cells[3,2] := '1';
      StringGrid1.Cells[1,3] := '003';
      StringGrid1.Cells[2,3] := '王五1';
      StringGrid1.Cells[3,3] := '1';
      StringGrid1.Cells[1,4] := '004';
      StringGrid1.Cells[2,4] := '王五2';
      StringGrid1.Cells[3,4] := '0';
      StringGrid1.Cells[1,5] := '005';
      StringGrid1.Cells[2,5] := '王五3';
      StringGrid1.Cells[3,5] := '1';
      StringGrid1.Cells[1,6] := '006';
      StringGrid1.Cells[2,6] := '王五4';
      StringGrid1.Cells[3,6] := '0';
      StringGrid1.Col := 3;
      StringGrid1.Row := 6;
    end;procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
      var
       i:integer;
    begin
      if Ord(key) = 38 then
      begin
        for i := (StringGrid1.Row - 1) Downto 1 do
          if StringGrid1.Cells[3,i] = '0' then
          begin
            StringGrid1.Row := i;
            StringGrid1.Col := 3;
            Exit;
          end;
      end;end;以上代码调试通过!
      

  4.   

    procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    var
       i:integer;
    begin
      if Ord(key) = 40 then
      begin
        for i := StringGrid1.Row to 5 do
        begin
          if StringGrid1.Cells[2,i+1] = '1' then
          begin
            StringGrid1.Row := i;
            Exit;
          end;
        end;
      end;
      if Ord(key) = 38 then
      begin
        for i := StringGrid1.Row downto 1 do
        begin
          if StringGrid1.Cells[2,i-1] = '1' then
          begin
            StringGrid1.Row := i;
            Exit;
          end;
        end;
      end;
    end;