如题

解决方案 »

  1.   

    在Onclick中判断是否为点击Title
      

  2.   

    因为StringGrid是不分Title的,建议在OnSelectCell事件中看ACol是否为0,然后再处理。
      

  3.   

    在CLICK事件判断当前行列是否为TITLE的行列。
      

  4.   

    我把问题详述一遍,
    我继承TstirngGrid做了一个控件,想让它响应TitleClick,该如何进行
      

  5.   

    三个方法:
    1、StringGrid被点击后,判断是不是第0行。
    2、用第三方控件。
    3、为什么不用ListView呢?
      

  6.   

    to 小马的拳
    1,StringGrid的Fixed根本不响应OnClick事件
    2,版权,费用,安全,。。
    3,用StringGrid的目的是显示不定几列的汇总,并同时具有数据网格的特点
      

  7.   

    TO 楼主:
         本人觉得楼主是否可以换个角度考虑这个问题。
         如果你是想显示不定列的汇总。 可以考虑换个数据集控件。
         TClientDataSet。用它可以创建一个虚拟的表。你可以显示
         任意你想显示的东东。当然,数据浏览控件还是用DBGrid。    如果需要,可以给你源码。
      

  8.   

    To 水男人,
    谢谢,但是DbGrid无法生成汇总行,例如:
        商品名    数量
         图书       3
         铅笔       5
    合计            8
      

  9.   

    我自己解决了,可以在MouthDown中写代码,计算鼠标位置
      

  10.   

    (*//
    标题:字符网格排序
    说明:升序、降序;示例点击标题排序
    设计:Zswang
    日期:2002-04-27
    支持:[email protected]
    //*)///////Begin Source
    function StringGridRowSwap(mStringGrid: TStringGrid;
      mFromRow, mToRow: Integer): Boolean;
    var
      S: string;
    begin
      Result := False;
      if (mToRow = mFromRow) then Exit;
      if not Assigned(mStringGrid) then Exit;
      if (mFromRow < 0) or (mFromRow >= mStringGrid.RowCount) then Exit;
      if (mToRow < 0) or (mToRow >= mStringGrid.RowCount) then Exit;
      try
        S := mStringGrid.Rows[mFromRow].Text;
        mStringGrid.Rows[mFromRow].Text := mStringGrid.Rows[mToRow].Text;
        mStringGrid.Rows[mToRow].Text := S;
      except
        Exit;
      end;
      Result := True;
    end; { StringGridRowSwap }function StringGridRowSort(mStringGrid: TStringGrid;
      mColIndex: Integer; mDesc: Boolean = False): Boolean;
    var
      I, J: Integer;
    begin
      Result := False;
      if not Assigned(mStringGrid) then Exit;
      if (mColIndex < 0) or (mColIndex >= mStringGrid.ColCount) then Exit;
      for I := mStringGrid.FixedRows to mStringGrid.RowCount - 2 do
        for J := I + 1 to mStringGrid.RowCount - 1 do
          if mDesc then
            if mStringGrid.Cells[mColIndex, I] < mStringGrid.Cells[mColIndex, J] then
              StringGridRowSwap(mStringGrid, I, J)
            else
          else if mStringGrid.Cells[mColIndex, I] > mStringGrid.Cells[mColIndex, J] then
            StringGridRowSwap(mStringGrid, I, J);
      Result := True;
    end; { StringGridRowSort }
    ///////End Source///////Begin Demo
    procedure TForm1.StringGrid1MouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    {$J+}
    const
      vOldCol: Integer = -1;
    {$J-}
    var
      vCol, vRow: Integer;
    begin
      if Button = mbRight then Exit;
      TStringGrid(Sender).MouseToCell(X, Y, vCol, vRow);
      if (vRow < 0) or (vRow >= TStringGrid(Sender).FixedRows) then Exit;
      StringGridRowSort(TStringGrid(Sender), vCol, vOldCol = vCol);
      if vOldCol = vCol then
        vOldCol := - vOldCol
      else vOldCol := vCol;
    end;
    ///////End Demo
      

  11.   

    procedure TForm1.StringGrid1MouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      if Y < StringGrid1.RowHeights[0] then
      begin
        //在这里可以计算出点击了哪个Title(根据列总长度(用TCustomGrid.ColWidths
        //得到)和X)
      end;
    end;—————————————————————————————————
    宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
    —————————————————————————————————
      

  12.   

    to foodbird(苯鸟) 
    //原文:
     // 我自己解决了,可以在MouthDown中写代码,计算鼠标位置   可以散分了吧,实际上你用的和大家说的是一致的,只是使用的事件不同,效果是一样的,不信可以试试。
        
       :)