重载DBGrid的目标是这样的.
如果有这样的一张表,
部门编号 个人编号 姓名
1           1       jjljlk
1           2        ajjal
1           3        aljflad
2           1        adjakd
2           2        adksklaj
显示出来时,是这样的
部门编号 个人编号 姓名
1           1       jjljlk
            2        ajjal
            3        aljflad
2           1        adjakd
            2        adksklaj
查了一些资料,发现要重载OnDrawColumnCell(大概吧,我用的机子不能上网.).这个事件来自TCustomDBGrid.但是在TCustomDBGrid中只找到了FOnDrawColumnCell的声明,也找不到其实现.不过运气不错,找不了一个叫DefaultDrawColumnCell,知道在这个函数里有一个WriteText具体负责显示.但是就是没有找到有哪个地方使用到这个函数的.请指教.

解决方案 »

  1.   

    看看<<delphi7 從入門到精通>>, 如果不想買, 到書店翻一翻, 有你要的例子
      

  2.   

    在:Grouping and Aggregates
    Grouping
    The CdsCalcs example has a ClientDataSet component that extracts its data from the familiar Country dataset. The group is obtained, along with the definition of an index, by specifying a grouping level for the index:object ClientDataSet1: TClientDataSet
      IndexDefs = <
        item
          Name = 'ClientDataSet1Index1'
          Fields = 'Continent'
          GroupingLevel = 1
        end>
      IndexName = 'ClientDataSet1Index1'When a group is active, you can make it obvious to the user by displaying the grouping structure in the DBGrid, as shown in Figure 13.16. All you have to do is handle the OnGetText event for the grouped field (the Continent field in the example) and show the text only if the record is the first in the group:procedure TForm1.ClientDataSet1ContinentGetText(Sender: TField;
      var Text: String; DisplayText: Boolean);
    begin
      if gbFirst in ClientDataSet1.GetGroupState (1) then
        Text := Sender.AsString
      else
        Text := '';
    end;
      

  3.   

    可是我现在关心的是找不到OnDrawColumnCell的实现在什么地方,郁闷