|
Re: How do you find a TreeItem index by searching the Data fields ? [message #462366 is a reply to message #462258] |
Tue, 11 October 2005 13:58 |
Grant Gayed Messages: 2150 Registered: July 2009 |
Senior Member |
|
|
There isn't a way provided for locating a TreeItem based on its data.
indexOf(TreeItem) does an identity match, so this won't help you.
Depending on your context there may be a better approach than running
through the full Tree each time though. For example, since your indexes
seem to be static, just keeping an array with index->TreeItem mappings could
provide a quicker solution.
Grant
"TJ Forshee" <timforshee@bgdigital.com> wrote in message
news:dicbat$6id$1@news.eclipse.org...
> Here is my problem... I have a Tree and I am populating it from a
database.
> When I add a TreeItem to the tree, I am setting its Data field with the
> index of the database record ( .setData(Integer.toString(dbIndex)) ).
Now,
> if I read a record from the database, and I know the index I am looking
for,
> how can I easily find the TreeItem in the Tree ?
>
> I thought I could somehow use the .indexOf() function... but it requires a
> TreeItem as the parameter... but that is what I am looking for.... can I
> somehow create a 'dummy' TreeItem, do a setData of it to the index I am
> searching for, and call .indexOf(dummyTreeItem) ? or does the .indexOf
> require ALL fields fo the search item to match ?
>
> Hope I am making sense....
>
> Of course, I could create my own search function and just traverse the
Tree
> looking at each TreeItem's Data field.... just wondered if there was an
> easier way.
>
> TJ
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.03734 seconds