Topic: Using TreeView

I have a couple of questions about using the treeview component that don't seem to be covered by either Dmitry's examples or those by K245 on his website or the recent example of DRAMA2 posted by  .


1. Is it possible to use a variable to operate the filter rather than hardcoding it in the treeview settings page? I don't see a filter option published as a property in the component help.


2. Is there an easy way of working out the index position of the branches?


This maybe a moot problem if I can use a variable to alter the filter search. The problem occurs if I need to add items to the tree other than manually counting the number of items per node, Is there a way to customise the text on the menu popup when right clicking on the tree when the editing functions have been enabled?


3. If in the end I have to manually make the treeview in script, how do I  make headers/titles as the actual component allows under Settings? Options does not seem to be a published property


What I need to do is to select an item from a standard grid (the Master part) and then have this part 'open up' in a treeview which shows an assembly of parts under it.   


The attached images shows the result I want to get, I have manipulated the database manually to achieve what is in the image of the treeview.  The lower treeview is one I created manually.

Post's attachments

Attachment icon gridtotreeview.PNG 66.67 kb, 115 downloads since 2020-06-21 

On a clear disk you can seek forever

2 (edited by CDB 2020-06-21 07:15:37)

Re: Using TreeView

Just in case it is impossible to do what I'm hoping with the  TreeView component, I've temporarily added a table grid to the form.


[SOLVED] see bottom of post
For a reason I can't fathom, I'm unable to set row[0] to a text colour without clicking on the row. Making it bold on viewing works, it is just the text colour that doesn't show on view without clicking on it. I haven't tried placing a hidden button on the form and attach that to the font colour and then add a button click to the code below.


I'm now thinking I might make a tablegrid into a pseudo tree if my first post is impossible - that is row[0] displays as normal and then I make all subsequent rows move over by one column to the right or right align column[0].


The code that isn't automatically changing the font colour is below.

procedure Form1_TableGrid2_OnChange (Sender: TObject);
var
 iRow,iCol, NumCol : integer;
begin
  NumCol := form1.TableGrid2.Columns.Count -1;
  subOrdinateGrid;  //this formats the header and alignment
 // form1.TableGrid2.SetFocus;

  for iCol := 0 to NumCol do
  begin
    form1.TableGrid2.Cell[iCol,0].TextColor := clRed;
    form1.TableGrid2.Cell[iCol,0].FontStyle := fsBold
   
  end;
end;

*** The reason I couldn't get row[0] to show  a text colour without clicking was because elsewhere I had set the   TableGrid2.SelectRange to True for row[0].  Comment this code out and all works as expected.

Post's attachments

Attachment icon gridfont.PNG 87.22 kb, 120 downloads since 2020-06-21 

On a clear disk you can seek forever

3 (edited by derek 2020-06-22 14:37:12)

Re: Using TreeView

Hi Colin,
Not exactly the answers to any of your questions but just throwing a couple of thoughts out there (see attachment).
Option 1 would be just use some sort of 'grid within grid' view so as you scroll or click your way down, you see any 'sub-items' (doesn't have to be 'grid within grid' of course, could be 2 discrete grids - I was just trying to give it more of a 'treeview' feel - LOL!).
Option 2 would be to make your tablegrid look a bit more like a treeview but allowing you to filter the 'tree' by (in this example, assembly).
Maybe it can give you some ideas.
Derek.

Post's attachments

Attachment icon cdb treeview.zip 681.15 kb, 321 downloads since 2020-06-22 

Re: Using TreeView

Thank you for your code Derek, I particularly like the 'sub-pop-up-grid' idea, something I hadn't thought of at all.

On a clear disk you can seek forever

5 (edited by derek 2020-06-24 10:31:26)

Re: Using TreeView

Hi Colin,
I forgot to add the bit of code that enables you to click on the 'sub pop-up grid' and drag it around the screen (just in case it''s obscuring underlying data in the main tablegrid) - please see attached.
Derek.

Post's attachments

Attachment icon cdbtree.zip 340.94 kb, 307 downloads since 2020-06-24