• Delphi中StringGrid删除


    开发环境D7
    只是部分代码
    StringGrid1事先固定了行数为20,固定了一行为标题行

    ----实现单行删除内容(StringGrid1事先固定了行数为20,固定了一行为标题行),没有固定多少行的时候请适当改写,这个是本人测试代码

     1 var
     2   i:Integer;
     3 begin
     4   if StringGrid1.RowCount<2 then
     5   begin
     6     Exit;
     7   end;
     8   StringGrid1.Rows[StringGrid1.Row].Clear;
     9   if StringGrid1.Row=StringGrid1.RowCount-1 then
    10     Exit;
    11   for i:=StringGrid1.Row to StringGrid1.RowCount-2 do
    12   begin
    13     StringGrid1.Rows[i]:=StringGrid1.Rows[i+1];
    14     StringGrid1.Rows[i+1].clear;
    15   end;
    16 
    17 end;

    --------增加行

    StringGrid1.RowCount:=StringGrid1.RowCount+1;

    ---------减少行

    StringGrid1.RowCount:=StringGrid1.RowCount-1;

    ----------Showhint 单元格内容

    1 procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState;
    2   X, Y: Integer);
    3 begin
    4   if (StringGrid1.MouseCoord(x,y).X>StringGrid1.ColCount-1) or (StringGrid1.MouseCoord(x,y).X<0) then
    5     Exit;
    6   if (StringGrid1.MouseCoord(x,y).Y>StringGrid1.RowCount-1) or (StringGrid1.MouseCoord(x,y).Y<0) then
    7     Exit;
    8   StringGrid1.Hint:=StringGrid1.Cells[StringGrid1.MouseCoord(x,y).X,StringGrid1.MouseCoord(x,y).Y];
    9 end;

    --------------为单元格赋值    标题行赋值

     1 var
     2   i,j:Integer;
     3 begin
     4    StringGrid1.Cols[0].Text:='A000A';
     5    StringGrid1.Cols[1].Text:='B000B';
     6    for i:=0 to StringGrid1.ColCount-1 do
     7    begin
     8      for j:=0 to StringGrid1.RowCount-1 do
     9      begin
    10        if j=0 then
    11        begin
    12          Continue;
    13        end;
    14        StringGrid1.Cells[i,j]:=Format('i:=%d ;j:=%d',[i,j]);
    15      end;
    16    end;
    17 end;

    ---------------清空StringGrid的内容(标题行不清除)

    1 var
    2   i:Integer;
    3 begin
    4    for i:=1 to StringGrid1.RowCount-1 do
    5       StringGrid1.Rows[i].Clear;
    6 end;
  • 相关阅读:
    求字符串的全排列
    不能被继承的类
    Apache2启动错误以及Ubuntu update的错误
    从尾到头输出链表
    教你在网页上加QQ链接
    UL LI P 图片加文字无缝滚动
    ASP.net 里怎么对fileUpload控件上传的文件进行管理
    表单标签
    如果我为我女朋友做了这些,她一定会娇滴滴的说:“你真坏!
    break,continue,return
  • 原文地址:https://www.cnblogs.com/dmqhjp/p/15775009.html
Copyright © 2020-2023  润新知