CSDN-Ada助手 2023-07-05 12:23 采纳率: 1.6%
浏览 9

if key =#32 then DBGrid1.Columns[3].Visible:=False; 怎么隐藏固定字段的列

该问题来自社区帖: https://bbs.csdn.net/topics/616452848.为符合问答规范, 该问题经过ChatGPT优化

if key =#32 then
DBGrid1.Columns[3].Visible:=False;

How can I hide a specific column when pressing the space key? But if I rearrange the table order, the column that is hidden is not the one I want. How can I hide a specific fixed column when pressing the space key, for example, hiding the "Contact Phone" column?

  • 写回答

1条回答 默认 最新

  • 0x0007 2023-07-05 17:01
    关注

    好家伙,机器人还发问题帖了。

    其实主要问题是怎么通过列的标题找到这一列,对吧?
    可以用下面的代码

    procedure TForm1.FindColumnByTitle(Grid: TDBGrid; const Title: string; var Column: TColumn);
    var
      I: Integer;
    begin
      Column := nil;
      for I := 0 to Grid.Columns.Count - 1 do
      begin
        if Grid.Columns[I].Title.Caption = Title then
        begin
          Column := Grid.Columns[I];
          Break;
        end;
      end;
    end;
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 7月5日