I suspect this issue has been raised many other times in other messages, but i just haven't found them yet.
When I use FF_TreeView_DeleteAllItems every item removed from the treeview was calling my TVN_SELCHANGED event for the treeview.
My problem was easily resolved by setting a global variable just before calling FF_TreeView_DeleteAllItems and resetting after, then only doing anything in the TVN_SELCHANGED event if the global variable is reset.
However in our opinion here, this is a workaround and in theory FF_TreeView_DeleteAllItems should not trigger any of my code.
I expect that this is not a FireFly issue. The FF_Treeview_DeleteAllItems function is a simple wrapper around the api call. It does nothing special.
'-- FF_TreeView_DeleteAllItems ------------------------------------
'
' Remove all items from a TreeView.
'
' hWndControl: Handle of control (e.g. HWND_FORM1_TREEVIEW1)
'
' Returns: %TRUE if successful, %FALSE otherwise
'
'------------------------------------------------------------------
Function FF_TreeView_DeleteAllItems (ByVal hWndControl As Dword) As Long
' Do a check to ensure that this is actually a window handle
If IsWindow(hWndControl) Then
' Remove all items starting at the root of the TreeView.
Function = SendMessage( hWndControl, %TVM_DELETEITEM, 0, %TVI_ROOT)
End If
End Function
Here is a simple demo program that uses a Treeview and Command Button. I load a few nodes in WM_CREATE and when the Command Button is pressed, the Treeview is emptied. The only time that the TVN_SELCHANGE notification is called is when the FF_TreeView_SelectItem function is called in WM_CREATE.
Maybe you have code in the %TVN_DELETEITEM notification message that resets the node selection thus causing a TVN_SELCHANGE notification to fire. The TVN_DELETEITEM notification will fire for every node deleted during the FF_TreeView_DeleteAllItems message.
'------------------------------------------------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
hWndForm As Dword, _ ' handle of Form
ByVal UserData As Long _ 'optional user defined Long value
) As Long
Local hFirstNode As Long
Local hSecondNode As Long
Local hThirdNode As Long
hFirstNode = FF_TreeView_InsertItem(HWND_FORM1_TREEVIEW1, 0, "First Node", 1 )
hSecondNode = FF_TreeView_InsertItem(HWND_FORM1_TREEVIEW1, 0, "Second Node", 2 )
hThirdNode = FF_TreeView_InsertItem(HWND_FORM1_TREEVIEW1, hSecondNode, "Third Node", 3 )
' Expand and select the third node
FF_TreeView_SelectItem HWND_FORM1_TREEVIEW1, hThirdNode
End Function
'------------------------------------------------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
FF_TreeView_DeleteAllItems HWND_FORM1_TREEVIEW1
End Function
'------------------------------------------------------------------------------------------------------------------------
Function FORM1_TREEVIEW1_TVN_SELCHANGED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
ByVal lpNMTV As NM_TREEVIEW Ptr _ ' pointer to NM_TREEVIEW
) As Long
MsgBox "selchanged"
End Function
'------------------------------------------------------------------------------------------------------------------------
Function FORM1_TREEVIEW1_TVN_DELETEITEM ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
ByVal lpNMTV As NM_TREEVIEW Ptr _ ' pointer to NM_TREEVIEW
) As Long
MsgBox "deleteitem"
End Function
I'm afraid not, the only treeview event i use is TVN_SELCHANGED.
This is used to refresh a listview with information about the item selected in the treeview.
This seems very strange, i assume your example does not trigger the selchange event when deleting items?