DirView question

Post

Posted
Rating:
#1 (In Topic #1248)
Regular
bill-lancaster is in the usergroup ‘Regular’
 Have found DirView a handy way of displaying directories.
Is there a way to select (in code) a particular directory in the display?
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’

bill-lancaster said

Have found DirView a handy way of displaying directories.
Is there a way to select (in code) a particular directory in the display?

Yes by accessing the Dirview's internal TreeView object

Code (gambas)

  1.  
  2. Public Sub Form_Open()
  3.  
  4.   DirView1.ShowHidden = True
  5.   SelectDir(User.home &/ ".config", DirView1)
  6.  
  7.  
  8.  
  9. Private Sub SelectDir(Path As String, DView As DirView)
  10.  
  11.   Dim tv As TreeView = DView.Children[0]
  12.   tv[Path].Selected = True
  13.  
  14.  
  15.  


If you look at the DirView source code…
comp/src/gb.form/.src/File/DirView.class · master · Gambas / gambas · GitLab

You can see that when it is is created is first adds 1 TreeView object to itself, so the DirView.Children[0] is a TreeView.
So with the above code..
  Dim tv As TreeView = DView.Children[0]
tv is the TreeView, you can do all you can with a normal TreeView.

Code (gambas)

  1.   Dim tv As TreeView = DView.Children[0]
  2.   Print tv.Keys.Join("\n") ' list all the item keys
  3.  
  4.   tv[Path].Background = Color.yellow  ' make one item have yellow background
  5.   tv[Path].RichText = "<font color=green><b>" & tv[Path].Text & "</b></font>" ' change font color of one item and make it bold.
  6.  
Online now: No Back to the top

Post

Posted
Rating:
#3
Regular
bill-lancaster is in the usergroup ‘Regular’
 Does the trick nicely,
Thanks Bruce
Online now: No Back to the top
1 guest and 0 members have just viewed this.