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
I have the answer.
@lpNMTV.itemnew.lparam
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.
I got confused with that one, I could not work out how to get the required hItem handle.
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.
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
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.
Many Thanks
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.
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.
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.
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.
Cheers Paul.