在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 的行不选中,跳过去。
-- 代码 姓名 是否结婚
001 张三 0
002 里司 1
003 王五1 1
004 王五2 0
005 王五3 0
006 王五4 0
007 王五5 1 .....
现在的问题是:程序一运行,光标定位到stringgrid中的'是否结婚'的值是0的行,而且在进行上、下
键移动时,光标跳到还是0的行,即,'是否结婚'是1 的行不选中,跳过去。
解决方案 »
- 问题小白:不懂delphi的属性
- 把一个登录对话框做成dll,一旦连接数据库后,再关闭就无响应了
- ReportBuilder 报表设计器, 自定义纸张 页脚无法打印出来的问题 (100分)
- 请高手指教一个动态库问题
- DBGrid里,怎样禁止增加或插入行?
- 简单的问题请教
- 菜鸟提问,求各界高手来帮帮俺!
- 这种情况的企业对象应该如何设计其关系,如何处理更新?(内详),急!
- 求教:一个关于VCL较难的问题
- 呵呵!一個簡單問題,為什麼我動態改變panel的大小后,它里面的東西看不見了?
- 请问:如何按星期/自定义月份起始终止日期对数据库进行统计(一条SQL语句)?
- 为了大家少走弯路,我决定发起这么一个贴子---------关于Delphi的最适合阅读的书和最不适阅读的书?
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;
以上代码调试通过!
for i := 4 downto (StringGrid1.Row + 1) do
begin
//
end;
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;以上代码调试通过!
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;