Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 06-19-2014, 03:56 AM
delphimpd delphimpd is offline
Senior Member
 
Join Date: Oct 2006
Posts: 701
Default Finding Node Id

Thanks for the Help in advanced
I got this Code fro the web I am trying to store the selected Node Id to a listbox, then look for the stored id from the list to loacte and select the node on the tree view again.

I am getting a couple of compiler error not been able to identify why.
Thanks for the help

Regards,

Included is the zip sample
Attached Files
File Type: zip Treeview.zip (5.0 KB, 3 views)
Reply With Quote
  #2  
Old 06-19-2014, 06:32 AM
kolbasz kolbasz is offline
Senior Member
 
Join Date: Nov 2013
Posts: 841
Default

Hi delphimpd,

First remove JvExComCtrls, JvComCtrls from the uses clause. It's a reference to the Jedi library, you don't need that.

Code:
procedure TForm2.Button2Click(Sender: TObject);
var
  cNodeId : Integer;
begin
  if TreeView1.SelectionCount = 0 then
  begin
    ShowMessage('Please select a Treview item');
    Exit;
  end;
  cNodeId := TreeView1.Selected.AbsoluteIndex;
  if HTreeItemList.Items.IndexOf(IntToStr(cNodeId)) = -1 then
    HTreeItemList.Items.Add(IntToStr(cNodeId));
end;

procedure TForm2.Button3Click(Sender: TObject);
var
  cNodeID: Integer;
  FoundNode: TTreeNode;
begin
  if HTreeItemList.SelCount = 0 then
  begin
    ShowMessage('Please select a Listview item!');
    Exit;
  end;
  cNodeID := StrToIntDef(HTreeItemList.Items.Strings[HTreeItemList.ItemIndex],
 -1);
  if cNodeID <> -1  then
  begin
    for FoundNode in TreeView1.Items do
    begin
      if FoundNode.AbsoluteIndex = cNodeID then
      begin
        FoundNode.Selected := True;
        FoundNode.Focused := True;
        Break;
      end;
    end;
  end;
  TreeView1.SetFocus;
end;
Regards
Reply With Quote
  #3  
Old 06-19-2014, 01:40 PM
delphimpd delphimpd is offline
Senior Member
 
Join Date: Oct 2006
Posts: 701
Default

Good Morning Kolbasz

Thank you so much on your help.

I removed the references out of my Use Clause, it was there because I was trying some else, Thank you.


I tried your code, it compile just fine however, when I click on the button to find the node I get (List Index Out of Bound (-1) ). I tried playing with it but no luck, don't know if you can help me further.

Thanks

Best regards,
Reply With Quote
  #4  
Old 06-19-2014, 01:58 PM
kolbasz kolbasz is offline
Senior Member
 
Join Date: Nov 2013
Posts: 841
Default

You have to add then select an item in the listview.

Please change this line(Button3 click)
Code:
if HTreeItemList.SelCount = 0 then
begin
   //...
end
to
Code:
if HTreeItemList.SelCount <= 0 then
begin
//..
end;
this way everything should be fine.
Reply With Quote
  #5  
Old 06-19-2014, 03:01 PM
delphimpd delphimpd is offline
Senior Member
 
Join Date: Oct 2006
Posts: 701
Default

Hi Kolbasz

Thanks again for the help.

This is what I did, and since I am only going to allow only one item stored in this ListBox the item will be always item Cero.

I originally left your code as

Code:
if HTreeItemList.SelCount = 0 then
begin
   //...
end
but I added the below code so I dont have to auto select the list Box.

Code:
HTreeItemList.ItemIndex := 0;
This way I dont have to click on the ListBox for nothing.

The reason why it was giving me Index out of bound it was I was not actually clicking on the ListBox

If this can benefit others for any reasons, here is the attached zip file

As always
Thank you so much for the help.

Best regards
Attached Files
File Type: zip Treeview.zip (8.5 KB, 2 views)
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 12:35 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.