DirView question

Post your Gambas programming questions here.
Post Reply
bill-lancaster
Regular
Posts: 217
Joined: Tue Sep 26, 2017 3:17 pm
Location: NW England

DirView question

Post by bill-lancaster »

Have found DirView a handy way of displaying directories.
Is there a way to select (in code) a particular directory in the display?
BruceSteers
Legend
Posts: 2110
Joined: Thu Jul 23, 2020 5:20 pm
Location: Isle of Wight

Re: DirView question

Post by BruceSteers »

bill-lancaster wrote: Mon May 20, 2024 9:01 am 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


Public Sub Form_Open()

  DirView1.ShowHidden = True
  SelectDir(User.home &/ ".config", DirView1)

End


Private Sub SelectDir(Path As String, DView As DirView)
  
  Dim tv As TreeView = DView.Children[0]
  tv[Path].Selected = True

End




If you look at the DirView source code...
https://gitlab.com/gambas/gambas/-/blob ... =heads#L93

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.

  Dim tv As TreeView = DView.Children[0]
  Print tv.Keys.Join("\n") ' list all the item keys

  tv[Path].Background = Color.yellow  ' make one item have yellow background
  tv[Path].RichText = "<font color=green><b>" & tv[Path].Text & "</b></font>" ' change font color of one item and make it bold.
bill-lancaster
Regular
Posts: 217
Joined: Tue Sep 26, 2017 3:17 pm
Location: NW England

Re: DirView question

Post by bill-lancaster »

Does the trick nicely,
Thanks Bruce
Post Reply