edrpcn
604343
|
2022/9/10 18:02:38 |
感谢作者~! |
fengjianwei
35947
|
2008/10/28 21:13:12 |
为ADOQuery时,怎么处理也可以打印编号呢 |
jmahqh
33373
|
2008/3/19 14:59:06 |
谢谢楼主!实在太有用了!这正是我要找的! |
lsz100
32233
|
2007/12/15 10:03:14 |
列自适应在哪里呀 |
gudujian523
28513
|
2007/3/23 11:00:24 |
我刚学习delphi,也照着写了一下,控键都一样,可一运行那个DBGrid里面就是不能输入数据.我写的代码和我下载的一样.可以说什么都一样,可就是不能实现那个效果 |
jin_rose
27451
|
2006/12/7 14:29:02 |
区别: 这是Ehlib的帮助: Specifies whether the column width will be recalculated to set grid width equal to client width.
EhLib Software |
ronnievenn
27450
|
2006/12/7 14:12:35 |
谢谢,绝对是好东西! 但不太明白这和dbgrideh自带的autofitcolwidths有什么不同,哪位说明一下 |
bkpeony
27408
|
2006/12/2 21:42:00 |
谢谢jin_rose指点,二种方法我都将试一下。单从程序上看,如果不考虑数据库大小的话,好象还是第二种方法更简捷一点,而且不仅是在打印时会自动有值,在导出时也应该会自动有值,是吧。 再次感谢jin_rose 的指点。 |
jin_rose
27407
|
2006/12/2 14:38:43 |
如果只是在查询时用于显示一个序号,那很简单。 在设计期直接创建NO这个字段, procedure TForm1.ClientDataSet1CalcFields(DataSet: TDataSet); begin ClientDataSet1.FieldByName('no').AsString :=inttostr(ClientDataSet1.RecNo); end; 这样就自动有了一个序号。
如果你用的是ADOQuery的话,它同样也有RecNo,在同样的事件中处理一下就可以了。 这种写法,它是一个实际存在的字段,在打印时会自动有值 |
jin_rose
27406
|
2006/12/2 14:23:18 |
to:bkpeony 关于动态添加No字段,在DELPHI的帮助中有这样的代码,此方法我也常用于工作当中。 The following code creates and activates a client dataset in the form OnCreate event handler:
procedure TForm1.FormCreate(Sender: TObject);
begin with ClientDataSet1 do begin with FieldDefs.AddFieldDef do begin DataType := ftInteger; Name := 'Field1'; end; with FieldDefs.AddFieldDef do begin DataType := ftString; Size := 10; Name := 'Field2'; end; with IndexDefs.AddIndexDef do begin Fields := 'Field1'; Name := 'IntIndex';
end; CreateDataSet; end; end; |
bkpeony
27399
|
2006/12/1 18:14:37 |
试用一下,感觉很不错。另外还想请教一下楼主及各位大侠,有什么办法可以在程序运行中动态添加“no”这个虚拟字段吗? 楼主的打印时添加序列号方法虽然很好,但不太灵活,一定要事先把SQL查询语句写好,不能在运行过程中按特定条件进行查询。如果可以动态添加“no”字段,就比较灵活了。 |
bkpeony
27359
|
2006/11/28 22:28:33 |
DBGridEh用下来一直感觉很好,但一直受自动编号问题困扰,看来这次终于可以解决了,可以把程序做得更漂亮一点了。 |
kingjit
27296
|
2006/11/24 11:12:04 |
ehlib already have auto width function |
jin_rose
27121
|
2006/11/13 19:26:00 |
解决打印时没有序号的方法: cs1 是 TClientDataSet 1.右击cs1,添加一个字段 No 是 string(10) object cs1: TClientDataSet Aggregates = <> Params = <> AfterScroll = cs1AfterScroll Left = 40 Top = 80 object cs1GoodsName: TStringField FieldName = 'GoodsName' end object cs1GoodsNumber: TIntegerField FieldName = 'GoodsNumber' end object cs1No: TStringField FieldName = 'No' Size = 10 end end
procedure TForm1.cs1AfterScroll(DataSet: TDataSet); begin if DBGridEh1.SumList.RecNo <> -1 then begin cs1.Edit; cs1.FieldByName('no').AsString :=IntToStr(DBGridEh1.SumList.RecNo); end; end;
procedure TForm1.DBGridEh1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState); begin DBGridRecordSize(Column); if Column.Index = 0 then if (DBGridEh1.SumList.RecNo <> -1) then if (DBGridEh1.SumList.RecNo = 0 ) then DBGridEh1.Canvas.TextRect(Rect, Rect.Left + 3, Rect.Top + 2, IntToStr(1)) else DBGridEh1.Canvas.TextRect(Rect, Rect.Left + 3, Rect.Top + 2, IntToStr(DBGridEh1.SumList.RecNo)); end;
//PrintView procedure TForm1.PrintView1Click(Sender: TObject); begin DBGridEh1.Columns[0].FieldName := 'no'; self.PrintDBGridEh1.Preview; DBGridEh1.Columns[0].FieldName := ''; end;
//导出Excel uses ComObj;
procedure TForm1.oExcel1Click(Sender: TObject); var i,j : Integer; Excelid,xl: Variant; s : string; begin inherited; if cs1.RecordCount <= 0 then exit; try Excelid:=CreateOleObject('Excel.Application' ); except on Exception do raise exception.Create('无法创建Xls文件,请确认是否安装EXCEL') end; Excelid.Visible := True; Excelid.WorkBooks.Add; Excelid.caption := '演示程序'; Excelid.worksheets[1].range['A1:C1'].Merge(True); Excelid.WorkSheets[1].Cells[1,1].Value := '演示程序'; Excelid.worksheets[1].range['A1:C2'].HorizontalAlignment := $FFFFEFF4; Excelid.worksheets[1].range['A1:C2'].VerticalAlignment := $FFFFEFF4; //设置样式 Excelid.worksheets[1].Range['A1:C1'].Font.Name := '宋体'; Excelid.worksheets[1].Range['A1:C1'].Font.Size := 18; Excelid.worksheets[1].Range['A1:C2'].Font.bold:=true; //设置列宽 Excelid.worksheets[1].Columns[1].ColumnWidth := 5; Excelid.worksheets[1].Columns[2].ColumnWidth := 10; Excelid.worksheets[1].Columns[3].ColumnWidth := 10; //写标题 i:=2; Excelid.WorkSheets[1].Cells[i,1].Value := '序号'; Excelid.WorkSheets[1].Cells[i,2].Value := '商品名称'; Excelid.WorkSheets[1].Cells[i,3].Value := '商品数量'; //写值 i := 3; CS1.First; while not cs1.eof do begin Excelid.WorkSheets[1].Cells[i,1].Value := cs1.FieldByName('no').AsString; Excelid.WorkSheets[1].Cells[i,2].Value := cs1.FieldByName('GoodsName').AsString; Excelid.WorkSheets[1].Cells[i,3].Value := cs1.FieldByName('GoodsNumber').AsString;
cs1.Next; Inc(i); end; s := 'A2:C'+IntToStr(i-1); Excelid.worksheets[1].Range[s].HorizontalAlignment := $FFFFEFF4; Excelid.worksheets[1].Range[s].VerticalAlignment := $FFFFEFF4; //显示边框 Excelid.worksheets[1].Range[s].Borders.LineStyle := 1; end; |
QDZB
27119
|
2006/11/13 16:48:26 |
查看可以,但打印和导出时无顺号 |
aiguo
27055
|
2006/11/9 0:11:48 |
谢谢. 自适应列宽? |
hhzxedu
27023
|
2006/11/6 20:48:34 |
刚刚下载用过,真的好用,而且速度似乎还可以。谢谢楼主了! |
qiu888
27019
|
2006/11/6 17:02:01 |
谢谢了!我用过这个方法也行,但不够作者的方法简便:
procedure TfrmMain.DBGridEh1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState); var iRecNo: Integer; begin if (Column.FieldName <> 'VID') then //'VID'为用于显示编号的一个空字段名称 Exit; iRecNo := Column.Field.DataSet.RecNo; if (iRecNo > 0) then (Sender as TDBGridEh).Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, Format(' %.d', [iRecNo])); end; |
scottrayn
27013
|
2006/11/6 12:22:21 |
正需要这东西呢,谢谢 |
rongxingdelphi
26999
|
2006/11/5 21:26:34 |
谢谢`~~ |