怎么让DBGrid1的左边始终都有序列号???
也就是说不管其它数据怎么变,左边第一列始终都是按1、2、3、4、。排列下去了~~~
也就是说不管其它数据怎么变,左边第一列始终都是按1、2、3、4、。排列下去了~~~
解决方案 »
- webbroswer 自动填表在Application.ShowMainForm := False;下无法运行
- delphi 树tree递归求差
- idhttp如何post xml数据,
- 如果提取网页中的元素信息
- 怎么取adoquery当前记录的某字段
- 我要遍历本机的所有驱动器,目录和子目录下的所有文件,该怎么办
- 关于数字通信的一个问题,请大家帮个忙!时间紧迫!
- 有和java通用的des加密吗?
- 如何拖动Treeview的子节点到任意父节点?
- 计算器
- 这个问题了N次了,怎么都没人帮忙回答,是不是CSDN没高手?
- 一个程序,要把一些初始值(如:上次关闭窗口的位置。。。。)的消息的话,一般是怎么办?
在TCustomGrid.SetColWidths事件改为:
procedure TCustomGrid.SetColWidths(Index: Longint; Value: Integer);
begin
if FColWidths = nil then
UpdateExtents(FColWidths, ColCount, DefaultColWidth);
if Index >= ColCount then InvalidOp(SIndexOutOfRange);
if Value <> PIntArray(FColWidths)^[Index + 1] then
begin
if Value < 12 then Value := 30; //新增
ResizeCol(Index, PIntArray(FColWidths)^[Index + 1], Value);
PIntArray(FColWidths)^[Index + 1] := Value;
ColWidthsChanged;
end;
end;修改DBGRID.pas
在procedure TCustomDBGrid.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);事件加
找到下面这一行
FIndicators.Draw(Canvas, ALeft,
(ARect.Top + ARect.Bottom - FIndicators.Height) shr 1, Indicator, True);
if ACol <0 then
begin
Canvas.TextRect(ARect,0,(ARect.Top + ARect.Bottom - FIndicators.Height) shr 1
,inttostr(self.DataSource.DataSet.RecNo));
end; //新增
要求要保持不变哦~~不管其它字断怎么变,它都是固定的!
楼主是不是想要这个效果?
http://webmail.21cn.net:8082/tmp/230363_fsb:21cn_net/grideh.JPG
如果楼主要的效果是这样的,实现方法有2个:
1.每个左边放1个Panel,panel上写上1.2.3.4.5...
2.用DbgridEh在可能引起dbgrideh重画的地方写如下代码:var
I:Integer;
begin
for I:=0 to DBGridEh2.RowCount-2 do
begin
DBGridEh2.Canvas.Brush.Color:=clBtnFace;
DBGridEh2.Canvas.TextOut(1,DBGridEh2.TitleHeight+5+(i*(DBGridEh2.RowHeight+1)),InttoStr(I+1));
end;
end;
要设置DBGridEh的TitleHeight和RowHeight.
http://webmail.21cn.net:8082/fcgi/file/grideh.JPG?action=download&filename=/1101365622
2.在这个字段的OnGetText事件中写:
Text:=InttoStr(Sender.DataSet.RecNo);
3.在DBGrid中使用这个字段即可.
在DBGrid中,可以让序号字断固定不变吗?不论后面的SQL语句有变化~~~
如果SQL语句有变化,只要字段不变就行。如果字段变了,这个方法就不行。
var i:integer
adoquery.first;
for i:=1 to anumber(自己设定一个值) do begin
adoquery.fieldbyname('xu').asinteger:=i;
adoquery.next;
end;
adoquery.first;
2、如果有某个字段是按顺序排序的,例如1 2 4 6 7 (字段名:编号)
select (select count(*) from table1 where 编号<a.编号) from table1 a
3、如果是access,建立临时表,再用sql 命令 alter table 新建一自动编号字段
4、如果是sql server ,用sql的 indentity函数
5、如果是oralcal,--------->我不知道,我没用过,看,我连名字都拼错了。