PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: John Messingham on October 30, 2004, 04:30:06 PM

Title: Treeview Question
Post by: John Messingham on October 30, 2004, 04:30:06 PM
Hi,

I am trying to retrieve the lParam from a treeview, I have tried to get the prameter in the treeview_selchanged event. Has anyone got any sample code for this.

Many Thanks
Title: Treeview Question
Post by: John Messingham on October 30, 2004, 05:01:31 PM
I have the answer.


@lpNMTV.itemnew.lparam
Title: Treeview Question
Post by: TechSupport on October 30, 2004, 05:12:33 PM
You can also use FireFly's built-in function called: FF_TreeView_GetlParam

Press the "F8" key while in the code editor for a complete list of built-in functions.
Title: Treeview Question
Post by: John Messingham on October 30, 2004, 05:26:06 PM
I got confused with that one, I could not work out how to get the required hItem handle.
Title: Treeview Question
Post by: John Messingham on January 21, 2005, 07:04:16 PM
Sorry to revisit this one, can you give me an example of getting the lparam from a treeview item when it is double clicked. I have had to take a break from using PB/FF in order to complete some other work and I am just picking it up again.
Title: Treeview Question
Post by: TechSupport on January 22, 2005, 11:23:17 PM
When the node changes you can retrieve the lParam directly from the notification message:


Function FORM1_TREEVIEW1_TVN_SELCHANGED ( _
                                       ControlIndex  As Long,            _  ' index in Control Array
                                       hWndForm      As Dword,           _  ' handle of Form
                                       hWndControl   As Dword,           _  ' handle of Control
                                       lpNMTV        As NM_TREEVIEW Ptr  _  ' pointer to NM_TREEVIEW
                                       ) As Long

'Method #1:
MsgBox "lParam =" & Str$(FF_TreeView_GetlParam(HWND_FORM1_TREEVIEW1, @lpNMTV.ItemNew.hItem))

'or, Method #2:
MsgBox "lParam =" & Str$(@lpNMTV.ItemNew.lParam)

End Function
Title: Treeview Question
Post by: Roger Garstang on January 23, 2005, 01:17:49 AM
You will probably want format$ instead of str$ though, str$ adds a space to positive numbers to make room for the minus sign on negative numbers so everything is spaced right.  That always gave me problems and I never use str$...not sure why they even kept it with format$ having more options.
Title: Treeview Question
Post by: John Messingham on January 23, 2005, 08:36:10 AM
Many Thanks
Title: Treeview Question
Post by: John Messingham on January 23, 2005, 08:57:16 AM
One last question about treeviews.

I have a cheetah database consisting of three fields:

ID
Name
Parent ID

As I read through the database I want to load the data into a treeview, if the Parent ID is greater than zero, I want to add the record under the node that has the Parent ID as it's lParam.

Is there a way to search a treeview using the lParam, or do I need to search through the whole treeview checking for the required lParam. If I need to search the whole treeview, what is the quickest way?

Although these questions may seem very basic, I am finding the answers very helpful in helping me understand how to use the windows api better.
Title: Treeview Question
Post by: John Messingham on January 24, 2005, 05:24:42 AM
On reflection, I could use the query functions in Cheetah. When I add a parent node, I could create a query on the database and get any records that go with the parent.
Title: Treeview Question
Post by: TechSupport on January 24, 2005, 08:49:36 AM
That seems like a pretty slow method. Having to create a query to fill every noe would seem like a resource hog - especially if you have a large database.

I don't use Treeviews very much but I may have some code that allows you to search the tree via the lParam. I will check and post as soon as I can.
Title: Treeview Question
Post by: TechSupport on January 24, 2005, 10:32:08 PM
Nope. I thought that I had treeview search code, but I don't. :(

Maybe you can maintain a TYPE structure in memory that trackes the treeview's item handle and the parent id.


TYPE Node_TYPE
   hItem as dword    'handle to the treeview node
   ParentID  as long  
END TYPE

global TV_Nodes() as Node_TYPE


As you are getting the data from the database and adding nodes, you can maintain the TV_Nodes array. When you need to search, you simply search the TV_Nodes array rather than the Treeview. I knwo that this is probably not ideal but it should be very fast and doesn't consume too much memory.
Title: Treeview Question
Post by: John Messingham on January 25, 2005, 05:44:16 AM
Cheers Paul.