AutoHotkey Community

It is currently May 27th, 2012, 1:02 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: TV_Find() for TreeView
PostPosted: December 12th, 2011, 1:09 pm 
Offline

Joined: August 28th, 2009, 11:17 am
Posts: 599
Location: Brighton, UK
Hi,

I think it would be very handy to have a TV_Find(string Text) function that would return the ID of an item based on the text of the item.

I did this in a function, but when running on a very large dataset, this can slow things down a lot:
Code:
TV_Find(VarText)
{
   Loop
   {
      ItemID := TV_GetNext(ItemID, "Full")
      if not ItemID
         break
      TV_GetText(ItemText, ItemID)
      If (ItemText=VarText)
         Return ItemID
   }
Return
}


David

_________________
With mixed feelings I am stepping down from all moderation responsibilities: http://www.autohotkey.com/forum/viewtopic.php?t=82906


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2011, 4:12 am 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Some thoughts:

I've found that it's nice to keep a copy of the treeview/listview data in an object in memory, in which case it would be much easier (and faster) to search:

Code:
; populate your treeview with the key for ItemID and text as value
tv := { base: { add: ObjTV_Add, delete: ObjTV_Delete } }

for k,v in ["one","two","three","four"]
    tv.Add(v)

msgbox % "item 'four' has ItemID == " ObjFind(tv, "four")

ObjFind(obj, text) {
    for k in obj
        if (obj[k] = text)
            return k
}

ObjTV_Add(this, name, ParentItemId = 0, Options = "") {
    this[TV_Add(text, ParentItemId, Options)] := name
}

ObjTV_Delete(this, ItemID) {
    this.remove(ItemID, "")
    TV_Delete(ItemID)
}


Note: I assumed this is AHK_L and answered accordingly because there is no development being done with basic, hence no point in 'wishing' something for it.

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2011, 12:05 pm 
Offline

Joined: August 28th, 2009, 11:17 am
Posts: 599
Location: Brighton, UK
Yes I was talking about _L. Although your object is very neat and works well for me, a newbie will find it difficult to make the function I made, let alone your object. So I still feel that this will be a very useful inbuilt function to have.

David

_________________
With mixed feelings I am stepping down from all moderation responsibilities: http://www.autohotkey.com/forum/viewtopic.php?t=82906


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group