Autor Beitrag
merlin83
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 89

Win 98, Win 2000, SuSE Linux 9.3 Prof
D7 Personal, D2k5 Personal, Kylix
BeitragVerfasst: Do 16.09.04 21:39 
Schönen guten Abend!

Ich verwende ein TreeView und erstelle dort eine Baumstruktur (was auch sonst). Nun möchte ich, dass ein neues Item markiert wird, nachdem es erstellt wurde. Ich weiß von dem Element nur den Namen (Text), der eindeutig ist, daran kann das Element also identifiziert werden. Ich will aber nicht extra den ganzen Baum durchgehen, jedes Item auf seinen Namen überprüfen, Index auslesen und dann markieren, das wäre zu umständlich. Gibt es eine andere Möglichkeit?

Vielen Dank im Voraus!

_________________
If ProblemExists=True
Then ProblemExists:=False;
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Do 16.09.04 21:40 
wie sonst, wenn du nur die bezeichnung hast?
alternativ HashedStringlIst mit den Bezeichnung an der Position des Indexes und dann mit IndexOf (macht aber ja auch nichts anderes als zu suchen)

und warum ist das kompliziert?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
function FindNodeByText(NodeText: string; StartNode: TTreeNode): TTreeNode;
var
 i: integer;
 wasfound: boolean;
begin
 wasfound := false;
 NodeText := UpperCase(NodeText);
 if NodeText <> '' then
  while StartNode <> nil do
  begin
   if Pos(NodeText, UpperCase(StartNode.Text)) <> 0 then
   begin
    result := StartNode;
    wasfound := true;
    break;
   end;
   StartNode := StartNode.GetNext;
  end;
 
 if not wasfound then
  result := nil;
end;


mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)


Zuletzt bearbeitet von GSE am Do 16.09.04 21:46, insgesamt 2-mal bearbeitet
merlin83 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 89

Win 98, Win 2000, SuSE Linux 9.3 Prof
D7 Personal, D2k5 Personal, Kylix
BeitragVerfasst: Do 16.09.04 21:43 
Ja, das habe ich gefragt. Die Antwort hat nicht wirklich geholfen...
Kann doch auch sein, dass es ne Methode gibt, mit der man die Items direkt ansprechen kann.

_________________
If ProblemExists=True
Then ProblemExists:=False;
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Do 16.09.04 21:45 
TreeView.Items ?

s. Code in meinem ersten Posting...

mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
merlin83 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 89

Win 98, Win 2000, SuSE Linux 9.3 Prof
D7 Personal, D2k5 Personal, Kylix
BeitragVerfasst: Do 16.09.04 21:48 
Gut, das ist zwar keine Ideallösung, aber das passt schon. Vielen Dank!

_________________
If ProblemExists=True
Then ProblemExists:=False;
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Fr 17.09.04 10:40 
Zitat:

Nun möchte ich, dass ein neues Item markiert wird, nachdem es erstellt wurde.


wenn du ein item gerade erstellt hast, dann hast du doch den knoten. dann einfach

ausblenden Delphi-Quelltext
1:
Knoten.Selected := True;					


und schon ist der knoten im baum ausgewählt.
merlin83 Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 89

Win 98, Win 2000, SuSE Linux 9.3 Prof
D7 Personal, D2k5 Personal, Kylix
BeitragVerfasst: Fr 17.09.04 11:18 
Nein, habe ich eben nicht, weil ich es nur anhand seines Namens erstellt habe. Aber mit der Funktion von GSE funktionierts auch.

_________________
If ProblemExists=True
Then ProblemExists:=False;
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Fr 17.09.04 13:09 
also wenn ich

ausblenden Delphi-Quelltext
1:
Knoten := Tree.Items.Add (nil'test');					


mache, dann habe ich einen knoten...
vielleicht solltest du den knoten einfach dort schon selektieren, wo du ihn erstellst.