300分!!!不够再加!有本事的兄弟来拿!dbgrid在没有数据的时候如何也显示多行!(但是能编辑)帮顶者有分! (300分)

  • 主题发起人 主题发起人 netlangz
  • 开始时间 开始时间
用CLIENTDATASET就可以插入空记录.
 
不太清楚楼主想要干什么!
既然没有数据何必要显示多行?
 
http://www.efile.com.cn/efile/dfw@97546/2.JPG

自己画
 
procedure TForm1.Button1Click(Sender: TObject);
begin
dbgrideh1.RowCount := 10;
end;
啧啧,你可说好了啊,这样就可以了。
 
方案一,使用topgrid
方案二,使用ClientDataSet 插入空记录
 
to hfghfghfg:能否说详细点?
to lich:topgrid?能说详细点吗?谢谢!
 
procedure TFrm_main.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var
myrect, myrect2, myrectTemp1, myrectTemp2: TRect;
str, strV, str2, str3: string;
i: integer;
begin

myrect := Rect;
myrect.Top := myrect.Top + 3;
myrect.Left := myrect.Left + 3;
myrect.Right := myrect.Right - 3;
try
with TStringGrid(Sender) do
begin

Canvas.Font := font;
str := cells[ACol, ARow];
if gdSelected in State then
begin
Canvas.Brush.Color := $00C07F3A;
Canvas.Font.Color := Clwhite;
end
else
if gdFixed in State then
begin
Canvas.Brush.Color := clbtnface;
Canvas.Font.Color := Clblack;
end
else
begin
Canvas.Brush.Color := Color;
Canvas.Font.Color := Clblack;
end;

Canvas.FillRect(Rect);

if arow < FixedRows then

drawtext(Canvas.Handle, pchar(str), -1, myrect, DT_CENTER)

else
begin
if acol < 1 then
begin

if isSend(str) then
begin
Canvas.Font.Color := Clred;

drawtext(Canvas.Handle, pchar(getComName(str)), -1, myrect, DT_RIGHT);
ImageList1.Draw(Canvas, (rect.left + rect.right - 0) div 2, (rect.top + rect.Bottom - 16) div 2, 3);
myrect.Right := rect.Left + (rect.left + rect.right) div 2 - 4;
drawtext(Canvas.Handle, pchar(inttostr(length(cells[1, ARow]) div 2)), -1, myrect, DT_RIGHT)
end
else

if isReceive(str) then
begin
Canvas.Font.Color := Clblue;
drawtext(Canvas.Handle, pchar(getComName(str)), -1, myrect, DT_LEFT);
ImageList1.Draw(Canvas, (rect.left + rect.right - 32) div 2, (rect.top + rect.Bottom - 16) div 2, 4);
myrect.Left := rect.Left + (rect.left + rect.right) div 2 + 4;
drawtext(Canvas.Handle, pchar(inttostr(length(cells[1, ARow]) div 2)), -1, myrect, DT_LEFT)

end
else
drawtext(Canvas.Handle, pchar(str), -1, myrect, DT_CENTER)
end
else
begin
if isSend(cells[ACol - 1, ARow]) or isReceive(cells[ACol - 1, ARow]) then
begin
if isSend(cells[ACol - 1, ARow]) then
Canvas.Font.Color := Clred
else
Canvas.Font.Color := Clblue;

case ComboBox1.ItemIndex of
0:
begin
myrectTemp2 := myrect;

for i := 1 to length(str) div 2 do
begin
str3 := copy(str, 2 * i - 1, 2);
str3 := trim(char(strtoint('$' + str3)));
drawtext(Canvas.Handle, pchar(str3), -1, myrectTemp2, DT_LEFT);
inc(myrectTemp2.Left, 9);
if myrectTemp2.Left > myrectTemp2.Right then
Break;

end;

end;
1:
begin
myrectTemp1 := myrect;

for i := 1 to length(str) div 2 do
begin

str3 := copy(str, 2 * i - 1, 2);
drawtext(Canvas.Handle, pchar(str3), -1, myrectTemp1, DT_LEFT);
inc(myrectTemp1.Left, 20);
if myrectTemp1.Left > myrectTemp1.Right then
Break;

end;

end;
2:
begin
myrectTemp1 := myrect;
myrectTemp2 := myrect;
inc(myrectTemp2.Top, 17);

Canvas.MoveTo(rect.Left, rect.Top + 17);

for i := 1 to length(str) div 2 do
begin
str3 := copy(str, 2 * i - 1, 2);
drawtext(Canvas.Handle, pchar(str3), -1, myrectTemp2, DT_LEFT);

str3 := trim(char(strtoint('$' + str3)));
drawtext(Canvas.Handle, pchar(str3), -1, myrectTemp1, DT_LEFT);

inc(myrectTemp1.Left, 20);
inc(myrectTemp2.Left, 20);
if myrectTemp2.Left > myrectTemp2.Right then
Break;

end;
// Canvas.Pen.Color := clblue;

Canvas.MoveTo(rect.Left, rect.Top + 16);
Canvas.LineTo(rect.Right, rect.Top + 16);

end;
end;

end
else
begin
drawtext(Canvas.Handle, pchar(str), -1, myrect, DT_LEFT);

end;
end;
end;
Canvas.Pen.Color := clblack;
if acol = 0 then
begin
Canvas.MoveTo(rect.Left, rect.Top);
Canvas.LineTo(rect.Left, rect.Bottom);
end;
if Arow = 0 then
begin
Canvas.MoveTo(rect.Left, rect.Top);
Canvas.LineTo(rect.Right, rect.Top);
end;

Canvas.MoveTo(rect.Left, rect.Bottom - 1);
Canvas.LineTo(rect.Right - 1, rect.Bottom - 1);
Canvas.LineTo(rect.Right - 1, rect.top - 1);

end;
except
;
end
end;

 
晕,你用的stringgrid啊,往dbgrid中画怎么画呢?
如果用stringgrid处理数据库是在太麻烦了,兄弟!
 
to lich:topgrid?能说详细点吗?谢谢!
请问 那里有topgrid for delphi5 版本的下载,请告知,谢谢!
 
to lich:你说的topgrid连上数据源就不行了!
 
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
////
end;
 
hfghfghfg,:参数都不对?如何能套用?
 
1.直接画的解决方案趁早放弃,要是你成功了,估计你的能力自己写一个Grid控件都没有问题了。
2.显然不可能再寄托希望直接使用数据感应的好处了,你必须自己写处理代码。
3.根据1和2,最好办法是找一个好用的控件,不要再DBGrid上浪费时间了,StringGrid都比之更适合你的这个应用。
 
如果你昨天用STRINGGRID处理,现在一定已经处理完毕了。不要以为自己写点程序会很麻烦,不要以为写程序就是设置几个属性!!!!!不要轮为控件的奴隶!
 
to:楼上两位兄弟
^_^,如果我单纯的为了这个功能,我还需要这么发问吗?
做一套相对比较大的系统,需要一个团队,而团队的每个人如果都要那么麻烦的话,恐怕你也不会选择stringgrid!否则的话就......
如果我自己来画的话,恐怕也不是和写出dbgrid控见的工作量一样或者技术一样吧,如果你这样认为,那么证明你对dbgrid还不太熟悉!
 
强然要求用stringgrid.其实用stringgrid并不麻烦.并且安全多了.....
如果你想用dbgrid的话.你可以查看我的笔记,好像我的笔记收录了!!!!!!!!!!像任我行的管家婆或千方百剂也是用stringgrid来实现的........自已写一个类来做很快的呀
 
to:捡垃圾去上网的人
你有做好的类吗?能给出一些提示吗?600分全部奉送!
 
用Stringgrid处理好一点.很随随便便地由自己控制.
实际上dbgrid显示表也是遍历记录实现的.
还有把dbgrid的DefaultDrawing设为False,自己画,但较麻烦
 
另外你可以试这个方法
TStringgrid(dbgrid1).RowCount := 10;
可以这样做是因为Tdbgrid继承自TStringgrid.我没有试,你试一下.成的话散分.[:D]
 

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids;

type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
ADODataSet1: TADODataSet;
DataSource1: TDataSource;
procedure FormCreate(Sender: TObject);
procedure ADODataSet1AfterOpen(DataSet: TDataSet);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
ADODataSet1.Close;
ADODataSet1.FieldDefs.Add('F1', ftstring, 100);
ADODataSet1.FieldDefs.Add('F2', ftstring, 100);
ADODataSet1.FieldDefs.Add('F3', ftstring, 100);
ADODataSet1.FieldDefs.Add('F4', ftstring, 100);
ADODataSet1.CreateDataSet;
ADODataSet1.Open;
end;

procedure TForm1.ADODataSet1AfterOpen(DataSet: TDataSet);
var
i: integer;
begin
for i := DataSet.RecordCount to 10 do
begin
DataSet.Append;
DataSet.Post;
end;
DataSet.First;
end;

end.


这样好吗?
 
后退
顶部