TTXStringGrid组件V1.1.64 - 扩展delphi的标准TStringGrid组件(二)

 ===================================

本人log中所有未注明转载的文章和blog一般为本人原创或整理加工,
原创文章版权本人(lonefox)所有;转载文章版权归原作者所有;

http://blog.youkuaiyun.com/boythl

欢迎转载,但请注明出处,保留作者和版权信息。

===================================

   几个月前因为项目需要,本人扩展了标准TStringGrid组件,并命名为TTXStringGrid; 这是TTXStringGrid的升级版V1.1.64; 经过本人一段时间测试,消灭了大部分bug。

   主要增加对单元格个性化设置的支持;接口为TTXStringGrid的CellConfigs属性或CellConfig[ACol, ARow]属性,但请注意,单元格设置只支持运行时设置;不支持design-time修改(想想一个1000行*100列的表格,设计时显示该属性的话。。。);TTXStringGrid增加了几个事件。

   所谓的单元格个性化设置和列的个性化设置功能相同。当一个单元格既有自己的特定设置,它所属列也有特定设置时,将采用该单元格的特定设置,而不采用所属列的特定设置。

   使用文档目前没有时间整理。有问题请留言,lonefox保证第一时间回复。

 

   本来打算实现如同Excel中的冻结列功能; delphi的类层次给我痛头一击, TCustomDrawGrid类中很多该开放的函数不允许重载,若想实现该功能,基本上得放弃TCustomDrawGrid的大部分函数,自己再实现一次;只好放弃。

 

   1.1.64版下载地址:https://p-blog.youkuaiyun.com/images/p_blog_youkuaiyun.com/boythl/EntryImages/20081125/TXStringGridV1.1.64.jpg  下载后将扩展名修改为RAR即可,完整的源码包。因源码较长,不再在下文罗列。

   1.0版发布地址:http://blog.youkuaiyun.com/boythl/archive/2008/10/07/3026533.aspx

 

   下版本开发目标:1.支持更多种Editor。2.冻结列(就目前的继承组系谱来讲有点难度哦)。

 

   修改历史如下:

History:
  V1.0
  Class TTXStringGrid:
    1.[Add Columns],
     which can set/get columns of the grid as the same as TDBGrid

  V1.1
    Class TTXStringGrid:
    1.[add property CellConfig],
     through it,we can set/get special cells different from the parent column
    2.[add property CellConfigs],
      it's a collection of CellConfig.
    3.[delete event OnColEnter],
     we havn't implement it.
    4.[delete event OnColExit],
     we havn't implement it.
    5.[Add event OnCellExit],
      fired when the focus changed, select another cell or lost focus.
    Class TTXStringGridInplaceEdit
    1.[hide property DataList]
     Hide this property, because we don't support it in TTXColumns;
    2.[Modify method CloseUp]
     Modify it, so we can modify the cell's text with drop-down list
      even if its ReadOnly is true.
    Class TTXColumn
    1.[add property OnPickListCloseUp]
      Fired when user close the drop-down list inside the column.
    New Class TTXCellConfig
    1.[add property OnPickListCloseUp]
      Fired when user close the drop-down list inside a cell. Note, when it's fired,
    the OnPickListCloseUp event of its owner column won't be fired anymore.

    Bug corrected:
    Class TTXStringGrid:
    1.[modify property Columns],
      if the TTXStringGrid.ColCount is changed, the Columns.Count isn't updated.
    2.[modify method Create]
      Create default columns without BeginUpdate and EndUpdate, which is wrong.
    3.[modify method SetColCount]
     In it, around Columns.Add and Columns.delete, must has BeginUpdate and EndUpdate.
    4.[delete private member FTitleOffset]
      For solving the problem of the grid always draw a title,
      Replace all FTitleOffset with FixedRows; Deleted the parameter FTitleOffset.
    Class TColumnTitle:
    1.[Add method Assign]
      To solve sometimes the IDE messegeboxs "Can't assign a TColumnTitle to a TColumnTitle".
    Class TColumn:
    1.[modify method SetPickList]
      Havn't make sure FPickList not nil before call Assign.

 

   下面是一个动态创建Grid的简单实例,例子未包含所有新增功能:

  1. procedure TForm1.RzButton1Click(Sender: TObject);
  2. var sg:TTXStringGrid; v : TStringList;
  3. begin
  4.   sg:=TTXStringGrid.Create(self);
  5.   sg.Options := sg.Options + [goEditing, goRowMoving, goColMoving, goAlwaysShowEditor]; //使表格始终显示Editor
  6.   sg.Columns[1].PickList := self.Memo1.Lines; //下列列表内容,
  7.   sg.Columns[1].ButtonStyle := tcbsAutoSelect;//第二列的类型,必须设置PickList属性
  8.   sg.Columns[3].PickList := self.Memo2.Lines; //第四列的列表内容
  9.   sg.Columns[3].ButtonStyle := tcbsAutoSelect;
  10.   sg.Columns[3].ReadOnly := True;             //第四列只读,这里就只能用下拉列表选
  11.   sg.Parent := self;                          //动态创建时必须指定Parent
  12.   sg.Top := 0;
  13.   sg.Left := 0;
  14.   sg.visible := true;
  15.   sg.CellConfig[23].Color := clRed;        //第3列第4行的单元格显示红色背景色
  16.   sg.CellConfig[31].ButtonStyle := tcAutoSelect;
  17.   sg.CellConfig[31].PickList := self.Memo3.Lines;  //第四列第二行显示一个不同的下拉列表
  18.   sg.CellConfig[31].DropDownRows := 3;             //下拉列表只显示3行
  19.   sg.CellConfigs.Item[21] := sg.CellConfig[23];  //将第三列第四列的设置同样的赋给第三列第二行
  20.   sg.Columns[4].ReadOnly := True;                    //第五列只读
  21.   sg.CellConfig[4 , 1].ReadOnly := False;            //第五列第二行将可读写
  22.   sg.RowCount := 8;
  23.   sg.CellConfig[1 , 5].ButtonStyle := tcAutoSelect;
  24.   sg.CellConfig[1 , 2].PickList := Nil;              //第二列第三行的cell将不显示下拉列表,替换列设置效果
  25.   sg.CellConfig[1 , 3].ReadOnly := True;
  26.   sg.RowCount := 5;
  27.   sg.RowCount := 8;
  28.   sg.Width := 1000;
  29.   sg.Height := 800;
  30.   v := TStringList.Create;
  31.   v.Add('1');
  32.   v.Add('2');
  33.   v.Add('3');
  34.   v.Add('14');
  35.   v.Add('5');
  36.   sg.Columns[1].PickList := v;
  37.   with sg.Columns[2do begin
  38.       PickList := v;
  39.       DropDownRows := 15;
  40.       ButtonStyle := tcbsAutoSelect;
  41.   end;
  42. end;
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值