Another problem with tree view

Discussion in 'Questions (Windows Mobile)' started by RandomCoder, Feb 19, 2008.

  1. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Once again I find myself in need of help using the tree view control, I feel that I am becoming some what of a nuisance :sign0013:

    What I am attempting to do is use the SelectedNode to indentify the IndexOfNode, which works perfectly for the first level of the tree but returns -1 for the second level because node2's parent is node1.
    I've attempted changing the parent of node 2 amongst other things but all without success.

    Attached is a small sample program to try and show what I am trying to achieve.

    Please help once again :sign0085:
    Thanks,
    RandomCoder
     

    Attached Files:

  2. specci48

    specci48 Well-Known Member Licensed User

    Hello RandomCoder,

    does this code what you are trying to attempt???
    Code:
    Sub tree_afterselect
      
    If tree.Action="bymouse" Then      
        node1.value = tree.SelectedNode
        
    Do Until node1.IsRoot
          node1.value = node1.parent
        
    Loop      
        Row = tree.IndexOfNode(node1.value)
        
    Msgbox"Row "&table1.Cell("ID",Row)&" - "&table1.Cell("Message",Row))
      
    End If
    End Sub

    specci48
     
  3. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Specci48, your my new hero ;)

    Thats exactly what I've been trying to do but without success.
    Just couldn't get my head round where I was going wrong.

    Thanks so much,
    RandomCoder
     
  4. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Today I new problem....

    I've got a context menu working with my treeview which allows me to switch to different panels, i.e back to the main menu.
    But I would also like to use the context menu to perform certain actions on the selected node, such as reply or delete etc.
    Here is my problem.
    The AfterSelect event is not triggered by the context menu and so when I select to reply it is acting on the wrong value (node).
    Attached is a sample code to demonstrate the problem.....

    Any help, would as ever be greatly appreciated.

    Thanks,
    RandomCoder
     

    Attached Files:

  5. specci48

    specci48 Well-Known Member Licensed User

    Hi RandomCoder,

    sorry but I don't have an answer for this avaliable :sign0013:

    The Problem is not the AfterSelect event, because if you look carefully, using the context menu e.g. at the 5th entry, the 5th entry is highlited BUT the original node ist still seleced. The still selected node is marked with an outlined box. And after the MsgBox from the context menu is closed, the still selected "original" node is re-highlited again.

    A reason for this behavior could be that the context menu is added to the whole treeview and not to every single node. So the context menu is treated always the same ignoring on which position you called it.

    specci48
     
  6. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Hi Specci48,

    I too see the problem and tried to force the AfterSelect from within the Context Menu click event but still with no success.
    After exhausting all my idea's I thought it time to put it to the forum.

    Erel, do you have any idea's or is it possible to add this feature in a future release?

    Regards,
    RandomCoder
     
  7. specci48

    specci48 Well-Known Member Licensed User

    One small addition...

    Since some controls behave different on the desktop and on the device (and for the treeview there are A LOT of differences :sign0161:) I testet your code on the device.

    The result:
    On the device the context menu is called with a "tap and hold" action. If I run your original code, calling the context menu DOES select the new node since the device does not know, how long your stylus will be held on the display. The AfterSelect is fired and even overlaps the ContextMenu_Click event so the Sub ContextMenu_Click is never executed.
    A possible solution for a (device) working code could be: Put all your needed code into the ContextMenu_Click Sub and delete the AfterSelect event...


    specci48
     
  8. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Thanks, I'll persevere and report back.
    One other solution I've just thought of is to trigger the context menu click event using the afterselect of the treeview so that each time a node is selected it displays the context menu allowing the user to choose from the options.
    Its not ideal but it might work.

    I've also noticed that if I scroll down the nodes or click on the treeview control (not a node), then a node is highlighted and the afterselect event is fired. Therefore I can record which node it is, BUT if I then tap on that same node there is no way of detecting it.
    I think that a click event would also be useful for the treeview control.

    Regards,
    RandomCoder
     
  9. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Thanks, :)
    I can confirm that I have now got this working by removing the afterselect event and using the context menu.
    This does mean that I must now tap and hold the node then select an action but at least it performs the action on the correct node.
    I've requested a Click Event for the treeview control which will resolve this problem, see here http://www.basic4ppc.com/forum/showthread.php?p=10130#post10130.

    Regards,
    RandomCoder
     
Loading...