Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » tree.indexOf() always returning -1
tree.indexOf() always returning -1 [message #455194] Tue, 10 May 2005 08:52 Go to next message
Eclipse UserFriend
Originally posted by: CupertinoIndian.yahoo.com

I created a tree structure with depth 4 or 5. I am trying to find the
index of the item selected and I am always getting -1. Any ideas?

TreeItem[] treeItem = tree.getSelection();
if(treeItem != null && treeItem.length >= 0)
{
int index = tree.indexOf(treeItem[0]);
// index is always -1 ???
}
Re: tree.indexOf() always returning -1 [message #455248 is a reply to message #455194] Tue, 10 May 2005 17:04 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Tree.indexOf() only returns the index of the direct children of a node. Is
that what you are seeing?

"Cupertino Indian" <CupertinoIndian@yahoo.com> wrote in message
news:d5pt64$f9b$1@news.eclipse.org...
>
> I created a tree structure with depth 4 or 5. I am trying to find the
> index of the item selected and I am always getting -1. Any ideas?
>
> TreeItem[] treeItem = tree.getSelection();
> if(treeItem != null && treeItem.length >= 0)
> {
> int index = tree.indexOf(treeItem[0]);
> // index is always -1 ???
> }
Re: tree.indexOf() always returning -1 [message #455255 is a reply to message #455248] Wed, 11 May 2005 05:07 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: CupertinoIndian.yahoo.com

Ooh, I see. Thanks for information. I guess I need to iterate through
the whole tree to find the real location...unless somebody has better idea.


Steve Northover wrote:
> Tree.indexOf() only returns the index of the direct children of a node. Is
> that what you are seeing?
>
> "Cupertino Indian" <CupertinoIndian@yahoo.com> wrote in message
> news:d5pt64$f9b$1@news.eclipse.org...
>
>>I created a tree structure with depth 4 or 5. I am trying to find the
>>index of the item selected and I am always getting -1. Any ideas?
>>
>>TreeItem[] treeItem = tree.getSelection();
>>if(treeItem != null && treeItem.length >= 0)
>>{
>>int index = tree.indexOf(treeItem[0]);
>>// index is always -1 ???
>>}
>
>
>
Re: tree.indexOf() always returning -1 [message #459089 is a reply to message #455255] Mon, 01 August 2005 17:25 Go to previous message
Paul Singleton is currently offline Paul SingletonFriend
Messages: 37
Registered: July 2009
Member
Cupertino Indian wrote:
>
> Ooh, I see. Thanks for information. I guess I need to iterate through
> the whole tree to find the real location...unless somebody has better idea.

??? don't traverse the tree, but work back up to the root.

Get the selected item's parent item with getParentItem(), and if it
isn't null, get your item's index within its parent and then do it
all over again for the parent item until you reach the root

> Steve Northover wrote:
>
>> Tree.indexOf() only returns the index of the direct children of a
>> node. Is
>> that what you are seeing?
>>
>> "Cupertino Indian" <CupertinoIndian@yahoo.com> wrote in message
>> news:d5pt64$f9b$1@news.eclipse.org...
>>
>>> I created a tree structure with depth 4 or 5. I am trying to find the
>>> index of the item selected and I am always getting -1. Any ideas?
>>>
>>> TreeItem[] treeItem = tree.getSelection();
>>> if(treeItem != null && treeItem.length >= 0)
>>> {
>>> int index = tree.indexOf(treeItem[0]);
>>> // index is always -1 ???
>>> }
Previous Topic:extend NavigatorView transfer type (DND issue)
Next Topic:Hourglass!
Goto Forum:
  


Current Time: Sat Oct 24 20:09:14 GMT 2020

Powered by FUDForum. Page generated in 0.02174 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top