Access the value of a TreeView Checkbox

Post your Gambas programming questions here.
Post Reply
bazzvn
Posts: 18
Joined: Wednesday 22nd February 2017 11:06am
Location: Vietnam

Access the value of a TreeView Checkbox

Post by bazzvn »

I am running Gambas 3.15.2 under Debian Testing with the Plasma 5.20 desktop and I see that it is possible to show a checkbox for each item in a qt4/qt5 TreeView control. I would like to be able to iterate through the items in the TreeView and find those that have been marked with a check. I know how to iterate through the items in a TreeView, but I can't seem to find any documentation on how to return which items have been checked. I would be grateful for any help.
bazzvn
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Access the value of a TreeView Checkbox

Post by cogier »

....I see that it is possible to show a checkbox for each item in a qt4/qt5 TreeView control....
Can you post some code showing how you do this.
User avatar
Quincunxian
Posts: 171
Joined: Sunday 25th June 2017 12:14am
Location: Western Australia

Re: Access the value of a TreeView Checkbox

Post by Quincunxian »

In the treeview control, select ShowCheck in the parameter list.
This enables a single select only radio button next to each treeview item.

If you then set the mode parameter to multiple, the radiobutton changes to a checkbox and and you can select multiple items in any child node.

The Selection parameter of the treeview maintains a string array of the keys of the selected items.

To get a count of these is
My_Label.Text = Str(My_Treeview.Selection.Count)
If  (My_Treeview.Selection.Count > 0) Then 'some item has been selected.
Cheers - Quin.
I code therefore I am
bazzvn
Posts: 18
Joined: Wednesday 22nd February 2017 11:06am
Location: Vietnam

Re: Access the value of a TreeView Checkbox

Post by bazzvn »

Thanks Quin, that partly answers my question, but I'm not sure whether it will serve my purpose. Basically, I have a large collection of documents that are catalogued in an sqlite database. The idea is to assign tags and attributes to them so that they can be found quickly and cross referenced. I presently use the Current.Picture property to do it and it seems to work quite well (see attached example). I think I will stick with my current way for the present until I have more time to explore the ShowCheck property in Qt4/Qt5 TreeViews.

Cogier, I can't provide more information on the ShowCheck property than has already been provided by Quin, but any suggestions for a better way to do it than in my example would be welcome.
Attachments
TreeViewCheck.tar.gz
(16.98 KiB) Downloaded 209 times
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Access the value of a TreeView Checkbox

Post by cogier »

I could not see an easier way to do this. However, I have made a few changes that you may (or may not) like which include: -
  • The Form is now expandable
  • The list is now updated by a Timer, so you don't have to leave the TreeView to update
  • Added a simple NewItem Form, the Timer sorts the rest
  • aTemp now loaded in one line
I hope it helps.
TreeViewCheck_CO-0.0.1.tar.gz
(15.81 KiB) Downloaded 218 times
bazzvn
Posts: 18
Joined: Wednesday 22nd February 2017 11:06am
Location: Vietnam

Re: Access the value of a TreeView Checkbox

Post by bazzvn »

Thanks Cogier for taking the time to check the code. Your modifications result in more elegant code. I've never really understood how to use timers properly, so your addition of a timer was also instructive. The example project is just a subset of the code in my real FTags form, which includes additional code to create new tags and sub-tags, and for saving them to relevant tables in an sqlite database. Since it seems to work well, I use a similar approach for selecting tags to filter my database records (again inspired by the approach used in apps like Digikam and XnViewMP).

Thanks again.

Best wishes to all,
bazzvn
Post Reply