DELPHI里使用CXGRID给行加序号

语言:DELPHI表格控件:CXGRID界面如图:现在的问题是:在CXGRID新增一行时,在序号这一列按递增出现0001,0002,0003,序号列绑定了表字段名:XuHao.另外在删除时,比如删除了0002这一行,还剩下0001和0003,在新增一行时,需要从0004开始。请问该如何做

其实这个方法就是cxGrid范例中提供的,原范例在CellLevelMultiselectDemo目录下
把cxGridView里OptionsView选项中的两项修改成如下
OptionsView.Indicator = True
OptionsView.IndicatorWidth = 40//宽度
在customDrawIndicatorCell事件中填写
procedure TForm1.cxGrid1BandedTableView1CustomDrawIndicatorCell(
Sender: TcxGridTableView; ACanvas: TcxCanvas;
AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
AIndicatorViewInfo: TcxGridIndicatorRowItemViewInfo;
ATextRect: TRect;
// AStyle: TcxStyle;
aCV:TcxCanvas;
begin
if not (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
Exit;
aCV:=ACanvas ;
ATextRect := AViewInfo.ContentBounds;
AIndicatorViewInfo := AViewInfo as TcxGridIndicatorRowItemViewInfo;
InflateRect(ATextRect, -2, -1);
if AIndicatorViewInfo.GridRecord.Selected then //这个if段是为了在行号处把把选中的行号跟别的区分开,可不用
begin
aCV.Font.Style := Canvas.Font.Style + [fsBold]; 
aCV.Font.Color := clRed;
end
else
begin
 aCV.Font.Style := Canvas.Font.Style - [fsBold];
 acv.Font.Color := Canvas.Font.Color;
end;
Sender.LookAndFeelPainter.DrawHeader(ACanvas, AViewInfo.ContentBounds,
ATextRect, [], cxBordersAll, cxbsNormal, taCenter, vaCenter,
False, False, IntToStr(AIndicatorViewInfo.GridRecord.Index + 1),
// AStyle.Font, AStyle.TextColor, AStyle.Color);
acv.Font,acv.font.Color,acv.Brush.color );
ADone := True;
end;
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-08-20
用dbgrideh吧。。。自动的
DELPHI里使用CXGRID给行加序号
在customDrawIndicatorCell事件中填写 procedure TForm1.cxGrid1BandedTableView1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas;AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);var

cxGrid如何动态添加一个列,并把该列设置为有下
cxGrid delphi 1 使用TcxEditRepository控件, 增加一个combobox(如名称为cxcbb), 做好设置 2 绑定列 tvC.Properties := cxcbb.Properties;工具栏中拖一个TcxEditRepository控件, 双击, 在弹窗中添加combobox(如名称为cxcbb, 设置方法和普通combobox一样)2 绑定列 tvC.Properties := cxcbb.Properties...

delphi如何对数据表中的数据排序
方法很多哈 1.加入一个ADOQUERY。连接DATASOURCE。修改SQL语句可以达到效果 2..在DBGRID的点击事件中修改。方法这没没有现成了的,这个比较麻烦一点不推荐。3..这个是我极力推荐的,也是DELPHI的神器。把DBCRID这个控件换了,换成CXGRID这个是一个第三方空间,自己百度一下可以找出很多 ...

Delphi中:如何限制dbgird或者cxgrid某一列只能输入整数或小数。_百度...
与 Grid 组件不同,由于 dbGrid 是与数据源直接相联接的。通常情况下,如果设置好了数据库组件中字段列表,比如,将指定列的字段设置为数字型,当在 dbgrid 中输入时,delphi 会自动限制只能输入数字和小数点。其他场合,如果需要对输入进行限制,比如,限制某列(字符类型)只能输入整数或小数,可以考虑...

delphi中,cxgrid怎样将选中的单元格都赋为选中的第一行的值,并且数据集...
比如我选中了一个区域,3行3列,点一下“设为相同值”,就将第2行和第3行中这3列的值设为和第一行一样,对表格批量修改时用到 procedure TForm1.btn5Click(Sender: TObject);var fceFieldName:string;firFieldValue:Variant;SavePlace: TBookmark;begin \/\/cxGridDBTv1是TcxGridTableView fce...

delphi cxgrid 单条记录 多行显示
在查询的语句中分开就可以了,如:select 'a' as ColA,'b' as ColB... from tablename 当然,'a'可以用substring(columnname, 1, 1)来代替

delphi cxgrid获得当前行第一个列值 怎么写
在Grid内的TableView的OnSelectionChanged事件中,试试这样写:if Sender.Controller.SelectedRecordCount>0 then ShowMessage(Sender.Controller.SelectedRecords[0].Values[0]);

delphi下的cxgrid的列值转换问题
\/\/不改变查询语句\/\/1、在cxgrid里面的tabelview中新建一个人员名列,起个名colitem2,原有的为colitem1\/\/2、在该列的ongetdisplaytext,事件中,定义该列显示的数值ATextAtext:=Copy(ARecord.Values[ColItem1.Index],3,5);\/\/这句的意思是从0001张三获得atext的值 ...

delphi dbGridEh 做为编辑输入;可不可将固定第一行为编辑输入行!
固定在第一行控件本身貌似不可以,grid控件的特点就是随意。不过,可以在editbefore等事件中控制,比如,如果不是第一行就把readonly 设为true 自动排序首先必须要有索引。

delphi中cxgrid cheackbox 多选
根据第1步记录的主键值,定位回修改的那行,并将其 Check字段 修改为 True 大致代码如下 var tmpKey: string;begin if not qry.FieldByName('Check字段').AsBoolean then Exit; tmpKey := qry.FieldByName('key字段').AsString; qry.DisableControls; try qry.Filtered := False; ...

相似回答
大家正在搜