我在TreeView很多的列表,我想判断用户点击的是哪个列表,只能用Node.Txt的值来进行判断吗?还有没有其它的办法呀?
解决方案 »
- TDateTimePicker如果在设置maxdate及mindate后操作时做提示
- 多县城问题
- 如何防止用户通过控件向数据库写入空字符?
- 想删除数据库中某条记录blob字段里的图片,怎么编程?
- XP SP2系统,用Localhost不能访问本机MSSQL,用127.0.0.1可以,但用Localhost可以访问Web服务,请问为什么?有没有解决办法?
- report中画出的表格线打印出来太细了,怎么办?
- 不用第三方控件,如何在窗体中播放动画???
- 继续报表打印的问题,高手请进来,分数好说啊!!!
- 哪里有ADO的第一个升级包下载?
- 两台机器通过拨号上网,是否能够通过一台机器读取另一台机器的数据库,用SocketConnection开发的,恳请帮忙
- 菜鸟关于数据拷贝的问题,谢谢。(核桃)
- 郁闷了!救命啊!
type
pstr:^string;
var
pstr_str:pstr; ListItem := Items.Add;
str:=inttostr(i);
new(pstr_str);
pstr_str^:=str;
listitem.Data:=pstr;
然后根据data判断
var
root1,child1:TTreeNode;
pData:^String;
begin
with tr1.Items do begin
root1:=Add(nil,'root');
new(pData);
pData^:='level1';
root1.Data :=pData; child1:=AddChild(root1,'afasdf2');
new(pData);
pData^:='level2';
child1.Data :=pData; child1:=AddChild(child1,'afasdf1');
new(pData);
pData^:='level3';
child1.Data :=pData;
end;
end;procedure TForm1.tr1Click(Sender: TObject);
begin
if tr1.Selected <>nil then
ShowMessage(String(tr1.Selected.Data^));
end;
或者﹕以下來自delphi幫助﹕
The following code defines a record type of TMyRec and a record pointer type of PMyRec.type
PMyRec = ^TMyRec;
TMyRec = record
FName: string;
LName: string;
end;Assuming these types are used, the following code adds a node to TreeView1 as the last sibling of a specified node. A TMyRec record is associated with the added item. The FName and LName fields are obtained from edit boxes Edit1 and Edit2. The Index parameter is obtained from edit box Edit3. The item is added only if the Index is a valid value.procedure TForm1.Button1Click(Sender: TObject);var
MyRecPtr: PMyRec;
TreeViewIndex: LongInt;
begin
New(MyRecPtr);
MyRecPtr^.FName := Edit1.Text;
MyRecPtr^.LName := Edit2.Text;
TreeViewIndex := StrToInt(Edit3.Text);
with TreeView1 do
begin
if Items.Count = 0 then
Items.AddObject(nil, 'Item' + IntToStr(TreeViewIndex), MyRecPtr)
else if (TreeViewIndex < Items.Count) and (TreeViewIndex >= 0) then Items.AddObject(Items[TreeViewIndex], 'Item' + IntToStr(TreeViewIndex), MyRecPtr);
end;
end;After an item containing a TMyRec record has been added, the following code retrieves the FName and LName values associated with the item and displays the values in a label.procedure TForm1.Button2Click(Sender: TObject);begin
Label1.Caption := PMyRec(TreeView1.Selected.Data)^.FName + ' ' +
PMyRec(TreeView1.Selected.Data)^.LName;
end;