Help needed to improve this Folder Chooser

Discussion in 'Questions (Windows Mobile)' started by tsteward, Jan 20, 2009.

  1. tsteward

    tsteward Active Member Licensed User

    Open File dialog - When this dialog first opens, folders have no "+" icon to browse into subfolders until you click around. Then they start to appear but only on folders that you click on.

    To illustrate .. when this dialog opens, I get the following screen after clicking the "Storage Card" folder:
    [​IMG]


    .. And it’s only after clicking "Documents and Settings" and then AGAIN on "Storage Card" that I can browse the Storage Card:

    [​IMG]
    How can I make this code better. Code originally created by Erel. I assume it doesn't know if there are sub folders until you click on a folder, hence saving processor time.

    However I guess the main problem is when the user first selects a folder nothing happens, you need to click a different folder first.

    This only seems to happen on the PPC.

    Code:
    'FolderChooser is an example of using the TreeView library.
    'The folder nodes are added the first time the user presses on a folder.

    Sub Globals
        
    Dim root
    End Sub

    Sub App_Start
        
    If cPPC=True Then root="\" Else root = SubString(AppPath,0,3)
        Form1.show
        tree.new1(
    "form1",5,5,230,200)
        tree.AddImage1(AppPath & 
    "\folder.bmp")
        tree.AddImage1(AppPath & 
    "\openFolder.bmp")
        tree.ImageMode = 
    True
        tree.ImageIndex = 
    0 'sets all nodes to display the folder icon
        tree.SelectedImageIndex = 1 'sets the selcted node (each time) to display the open folder icon
        node1.new1
        node2.new1
        FindFolders(
    "\","tree")
    End Sub
    Sub FindFolders (pathnode'Finds all folders in a specific path
        WaitCursor(True)
        al1.clear
        DirSearch(al1,
    path)
        c = StrLength(
    path)
        
    For I =0 To al1.count - 1
            s=al1.item(i)
            
    If node = "tree" Then
                tree.AddNewNode(SubString(s,c,StrLength(s)-c))
            
    Else
                
    Control(node,Node).AddNewNode (SubString(s,c,StrLength(s)-c))
            
    End If
        
    Next
        
    If node = "tree" Then
            tree.ExpandAll
        
    Else
            
    Control(node,Node).Expand
        
    End If
        WaitCursor(
    False)
    End Sub

    Sub tree_AfterSelect
        
    If tree.action <> "bymouse" Then Return 'If the event was not raised by the user
    'When the user presses on a node, search for all folders inside.
        node2.value = tree.selectednode
        node1.value = tree.selectednode
        
    Dim s
        
    If node2.count = 0 Then 'If it is not 0 then the it was already opened
            Do Until IsNull(node2.Value) = True 'Find the full path of the current node
                s = node2.text & "\" & s
                node2.value = node2.parent
            
    Loop
            FindFolders(root & s,
    "node1")
        
    End If
    End Sub
     
  2. Mr_Gee

    Mr_Gee Active Member Licensed User

    I was thinking of doing the same thing (and save it as a *.bas)
    :)

    I think the answer lies in
    Code:
    Sub tree_AfterSelect
        
    If tree.action <> "bymouse" Then Return 'If the event was not raised by the user
    'When the user presses on a node, search for all folders inside.
        node2.value = tree.selectednode
        node1.value = tree.selectednode
        
    Dim s
        
    If node2.count = 0 Then 'If it is not 0 then the it was already opened
            Do Until IsNull(node2.Value) = True 'Find the full path of the current node
                s = node2.text & "\" & s
                node2.value = node2.parent
            
    Loop
            FindFolders(root & s,
    "node1")
        
    End If
    End Sub
     
    Last edited: Jan 20, 2009
  3. tsteward

    tsteward Active Member Licensed User

    Ok with a little further testing you can on first click select any folder other than "Storage Card" and it works fine.

    If first click is on storage card it wont open unless clicking another folder first.
     
  4. tsteward

    tsteward Active Member Licensed User

    Erel, :sign0085: Perhaps you have an idea how i might overcome this problem. When run the first time you click "Storage Card" nothing happens.

    Please
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    The problem is that on the device the first node is "partially" selected automatically and therefore the event is not fired when you press on the first node which is already selected.
    You can workaround this problem by adding these lines at the end of Sub FolderChooser.Initialize and manually open the first node:
    Code:
    tree.SelectedNode = tree.GetNode(0)
        tree.Action = 
    "bymouse"
        tree_AfterSelect
     
  6. tsteward

    tsteward Active Member Licensed User

    Thank you
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice