Queries for Derez and Filippo

RacingDog

Active Member
Licensed User
If you guys are around.........

Derez, in your TreeViewPlus library, I was messing around to find out how the CheckBoxes and AfterCheck event worked. I came to the conclusion that the only way of testing in the event to see if the just checked box was the Root node was to look for the node IsRoot being set and the control IndexOfNode is -1. Is that correct? Is there a better way?

Filippo, in your ListView library, is there any chance of adding an AfterCheck event similar to that found in TreeView and TreeViewPlus? Without it, it is difficult to respond immediately and also to know what has just changed and in which direction (checked or un-checked).

It is strange, but the two libraries also have this difference, in TreeViewPlus, checking a box seems to cause both AfterCheck and AfterSelect events (that may be just an effect of referencing the control in the AfterCheck handler (maybe?)), whereas ListView does not cause a SelectionChanged event on checking a box. I have no idea which is correct, or whether there is such a thing as correct and it is just a matter of taste!

As usual, I may be missing something obvious!

Still, they are both nice libraries to have.

Thanks in advance.
 

derez

Expert
Licensed User
Longtime User
RacingDog

I am very glad to see that someone is looking at this library...

I came to the conclusion that the only way of testing in the event to see if the just checked box was the Root node was to look for the node IsRoot being set and the control IndexOfNode is -1. Is that correct? Is there a better way?

The library is based on ControlsEx (by Erel or Agraham - I don't know) and the questions you ask should be asked with reference to the original, since I haven't changed anything on these events. The "plus" in the name is intended to say that there are more properties, like the Tag, font style and more.

edit: I checked the help and see this -
The AfterCheck event occurs after the user checks / unchecks a node.
You should use the CheckedNode property to find which node was checked.
Example:
...
'This sub will fire when the user checks or unchecks one of the nodes.
Sub tv_AfterCheck
If tv.Action = "unknown" Then Return
node.Value = tv.CheckedNode
Msgbox(node.Text,node.Checked)
End Sub

so you have the node's value after check. With TreeviewPlus you have also the node.Tag, so if you identify your nodes when creatibg them using Tags, then you have the node's identification immediately.
 
Last edited:

RacingDog

Active Member
Licensed User
Thanks Derez. AGraham, Erel, over to you wrt to my TreeView query above? Ta.
 

derez

Expert
Licensed User
Longtime User
But the simplest way is to check:

B4X:
node.Value = tv.CheckedNode
         if node.isroot then ....
 

RacingDog

Active Member
Licensed User
99.9% of the time that is correct. It would seem I was being mislead by a previously undetected bug which explains why I was seeing selection events. Basically, if the first click on the contol is check box, it doesn't matter which one, but as well as the check box being ticked, the Root node gets selected and a AfterSelect event occurs during the AfterEvent event, regardless of which node's check box you actually clicked on. This doesn't happen on a plain node selection being your first click. It doesn't happen on any subsequent click.

It also begs the question, if I refer to the Root node by node2.Value = tv.GetNode(0), why is node2.IndexOfNode -1? It should surely be tha same as the parameter to GetNode, afterall, it is the same node we are talking about.

I'll put it into the bug list so everyone is more likely see it. You like this, not a lot alot, but you will like it, Well Erel or Graham will :)
 

RacingDog

Active Member
Licensed User
Derez, in my current proggy it was avoidable (so far), but in general it may not be, but there seems to be a problem with the FindByText1 method. It seems to be expected that the item will be found, if it is not then a run time error is reported saying that length must be > 0. I have nothing called length, so it's down in the depths somewhere.

I was thinking of adding a "don't add a duplicate" check to my proggy which would need that method, but that would also have to work first time around when the key is not present.

The other finds and selects may behave the same, I haven't checked, didn't need to.

Ummm, it's not in the help, but it's listed in the pop up when editing, so what does ToString do and what is the syntax? Or was that just a debug tool that never quite got removed?
 

agraham

Expert
Licensed User
Longtime User
so it's down in the depths somewhere.
Not very far down, it's in FindByText1 itself. He needs to add a check for an empty string before attempting a SubString on it.

so what does ToString do and what is the syntax?
Every .NET object has a ToString() method inherited all the way back from the Object class itself at the top of the object inheritance hierarchy. The default is to return the Class name but on the desktop Framework many of the classes override it to give useful information. For example a Color object returns a string detailing its RGB components. The Compact Framework on the device doesn't do this much, presumably to save space, so it is less useful there.

The syntax is just Someobject.ToString. It is not very useful in Basic4ppc as you can only invoke it on library objects except when playing with the Door library where it is a useful way of seeing that the object you've picked up is the right one.

Msgbox(Obj1.RunMethod("ToString"))
 
Last edited:

derez

Expert
Licensed User
Longtime User
Thanks for the comment, i'll correct it soon.
What would you prefer as the return of the method in the case that the string to be found is empty ?
 
Last edited:

RacingDog

Active Member
Licensed User
Yes, an empty string, no point in making things complicated. But just to be safe, remember to run an eye over the other Find methods and selectbytag (he said being old and suspicious).

Thanks guys.
 

derez

Expert
Licensed User
Longtime User
Well, not exactly as you ask for but I updated, see the help file. Thanks again for the debugging :)

I'm not sure that the question is aimed at me
Agraham - yes it was aimed also to you, and I always appreciate, value and learn from your inputs.
 
Last edited:

RacingDog

Active Member
Licensed User
Just reading your comments for the library update on the other thread, you say you check for empty input strings. Ummm, that wasn't exactly the problem. When I said "It seems to be expected that the item will be found", I didn't mean that the search was failing because of the input string being empty, I meant it failed because the target was not in the tree.

So you have definitely improved it by checking the input, and a return of "-1" is as good as any, but, sadly, my original problem is still there.

In your sample program, tree_1.1.sbp, type in the text "mummy" then search, you'll see what I mean.
 

derez

Expert
Licensed User
Longtime User
OK OK, when explained slowly I understand fast...
corrected:
B4X:
if(st.Length > 0)
    {return st.Substring(0,st.Length-1) ;}
else
    {return "" ;}
 

RacingDog

Active Member
Licensed User
That's the one cheers!

And I do like the way we can distinguish between the two cases "-1" and "". Very good!
 
Top