为什么树节点的字体没有改变,在线等

visualcdotnet 2006-04-21 04:02:29
procedure TChdaForm.TrVwCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var
i:Integer;
Ds:TAdoDataSet;
begin
Ds:=TAdoDataSet.Create(nil);
try
Ds.Connection:=FCn;
for i:=0 to Node.Count-1 do
begin
Ds.CommandText:=' select isnull(f_color,0) as f_color,isnull(f_bold,0) as f_bold from '+TABLENAME+
' where '+BMFIELD+'='''+copy(Node.Item[i].Text,1,pos(' ',Node.Item[i].Text)-1)+''' and '+
' f_jb=(select isnull(f_jb,0)+1 from '+TABLENAME+' where '+BMFIELD+'='''+copy(Node.Text,1,pos(' ',Node.Text)-1)+''')';
Ds.open;
if Ds.Bof and Ds.Eof then Exit
else
begin
Ds.First;
with (Sender as TTreeview).Canvas.Font do
begin
Color:=Ds.FieldValues['f_color'];
case Ds.FieldValues['f_bold'] of
0: Style:=Style-[fsBold];
1: Style:=Style+[fsBold];
end;
end;
end;
Ds.Close;
end;
finally
Ds.Close;
Ds.Free;
end;
end;
...全文
123 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
飞天揽月 2006-04-23
  • 打赏
  • 举报
回复
不要这样写,效率太低了 自己把那些数据库代码去掉,就设置Color看看,肯定有效果,自己加断点好好看看
cloudtarget 2006-04-23
  • 打赏
  • 举报
回复
建议把select 语句放到展开节点事件中去,用树节点的data属性指向一个自己的对象,保存自己需要的数据, 然后在此自画事件中处理
type
PRec = ^TRec;
TRec = record
ID: string;
Mc:string;
Color: Integer;
Bold:Integer;
Flag: ShortInt;
end;
...
var
ptr: Prec;
...
with (Sender as TTreeview).Canvas.Font do
begin
if Assigned(Node.Data) and (copy(Node.Text,1,pos(' ',Node.Text)-1)=PRec(Node.Data)^.ID) then
begin
if TrVw.Selected=Node then Color:=clWhite
else Color:= PRec(Node.Data)^.color;
case PRec(Node.Data)^.bold of
0: Style:=Style-[fsBold];
1: Style:=Style+[fsBold];
end;
end;
end;
...
cloudtarget 2006-04-21
  • 打赏
  • 举报
回复
procedure TChdaForm.TrVwCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
var
i:Integer;
Ds:TAdoDataSet;
begin
Ds:=TAdoDataSet.Create(nil);
try
Ds.Connection:=FCn;
Ds.CommandText:=' select isnull(f_color,0) as f_color,isnull(f_bold,0) as f_bold from '+TABLENAME+
' where '+BMFIELD+'='''+copy(Node.Text,1,pos(' ',Node.Text)-1)+''' ';
Ds.open;
if Ds.Bof and Ds.Eof then Exit
else
begin
Ds.First;
with (Sender as TTreeview).Canvas.Font do
begin
Color:=Ds.FieldValues['f_color'];
case Ds.FieldValues['f_bold'] of
0: Style:=Style-[fsBold];
1: Style:=Style+[fsBold];
end;
end;
end;
finally
Ds.Close;
Ds.Free;
end;
end;
happyct 2006-04-21
  • 打赏
  • 举报
回复
ownerdraw = true;
canvas.textout or else
happyct 2006-04-21
  • 打赏
  • 举报
回复
我日,你还真不一般的牛鼻,把Select放到DrawItem里面去执行。。

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧