treeview问题(50分)

  • 主题发起人 主题发起人 zhousi
  • 开始时间 开始时间
Z

zhousi

Unregistered / Unconfirmed
GUEST, unregistred user!
点击treeview使当前节点ImageIndex从0变到1
结果点击后图象不发生变化,等我再次点击时,被选的节点图标不发生变化,前一次的图标
却变了
procedure Twjglmainf.FormShow(Sender: TObject);
var
Node:Ttreenode;
begin
Cds_jr_tree.Close;
Cds_jr_tree.CommandText:='select * from jr_tree where db_mang='''+'1'+'''';
Cds_jr_tree.Open;
while not Cds_jr_tree.Eof do
begin
Node:=TV_jr_tree.Items.Add(nil,Cds_jr_tree.FieldByName('fl_cname').AsString);
Node.ImageIndex:=0;
Cds_jr_tree.Next;
end;
//生成树
end;

procedure Twjglmainf.TV_jr_treeClick(Sender: TObject);
var
Node:Ttreenode;
begin
if TV_jr_tree.selected<>nil then
begin
node:=TV_jr_tree.Selected;
node.ImageIndex:=1;
end;
end;
 
很多人喜欢用TTreeView。
但总是问题多多?
 
同时改变Node.SelectedIndex和Node.StateIndex
 
点击时,被选的节点图标发生变化用
node.SelectedIndex
 
你搜一下,有一个完整的例子。好像是TipLoader
有个这方面的例子。
 
procedure Twjglmainf.TV_jr_treeClick(Sender: TObject);
var
Node:Ttreenode;
i:integer;
begin
if TV_jr_tree.selected<>nil then
begin
node:=TV_jr_tree.Selected;
node.SelectedIndex:=1;
//node.ImageIndex:=1;
node.StateIndex:=1;
end;
end;

大侠请问这三个有啥区别,啥关系呀
node.SelectedIndex:=1;
node.ImageIndex:=1;
node.StateIndex:=1;
 
忘了句话,ok了谢谢各位
 
1.ImageIndex
Specifies which image is displayed when a node is in its normal state and is not
currently selected.
property ImageIndex: TImageIndex;
Description
Use the ImageIndex property with the Images property of the tree view to
specify the image for the node in it抯 normal state.
2.SelectedIndex
Specifies the index in the tree view抯 image list of the image displayed for the node when
it is selected.
property SelectedIndex: Integer;Description
Use the SelectedIndex property to specify an image to display when the tree node
is selected.
3.StateIndex
ndicates which image from the StateImages list to display for the node.
property StateIndex: Integer;
Description
Use StateIndex to display an additional image for the node that reflects state
information. If StateIndex is -1 then
no state image is drawn.
不过对于StateIndex,我也不太明白用处是什么,
不过你可以看一下:http://www.delphibbs.com/delphibbs/dispq.asp?lid=204512
 
DELPHI的帮助里都说得很清楚了,在你这种情况下要用SelectedIndex属性。建议你要养成
利用帮助的习惯,其实DELPHI的帮助虽然没有微软的那么全,却也很不错,而且我感觉它是
一步一步的在进步。
 
to zw84611
还不如自己看帮助,全是英文
to michael.fly
我看帮助拉,但看不懂才问的嘛(本人英文是差了点555)
 
多人接受答案了。
 
后退
顶部