Page 1 of 1

alphabetical order: highlight first row

Posted: Tue Oct 21, 2014 9:14 am
by francof
Hi all,
let me explain: into a list field, I have about 200 lines containing names in alphabetical order and a group of buttons: one for each letter.
simply I want, clicking one of them, highlight the first row, and position myself, the contents of which starts with the letter corresponding to the pressed button.

be clear, I don't want to filter and to extract the rows corresponding to a certain letter, but only place the list in that point, to be visible the corresponding names.

thanks for help
franco

Re: alphabetical order: highlight first row

Posted: Tue Oct 21, 2014 9:37 am
by jmburnod
Hi Franco,

You can do that using a item's list of first letter of each line like this
"a,a,b,b,b,b,e,e,e,e"
And you have just to get the itemoffset(myletter).
You have now the num of the found line and you may play with "effective textHeight" and the vScroll of your group or list fld :D
Best regards
Jean-Marc

Re: alphabetical order: highlight first row

Posted: Tue Oct 21, 2014 4:02 pm
by francof
Hi Jean-Marc,
I understand the concept, and now I will try to do.... not sure of success, in case of need I will be back here.

best regards
franco

Re: alphabetical order: highlight first row

Posted: Tue Oct 21, 2014 5:23 pm
by francof
ok, I've done this for now :

Code: Select all

on mouseUp
   put fld "fldOrdineAlfabetico" into tAlfabeto
   put  itemOffset(the label of the target, tAlfabeto) into tNumRiga
end mouseUp
fldOrdineAlfabetico contains all the first letters, comma separated, of lines names.
I put the buttons of the letters into a group, and used their label like itemToFind.
now I must use it :?

edit: just

Code: Select all

set the hilitedLine of fld "fldVitigni" to tNumRiga
ciao
franco

Re: alphabetical order: highlight first row

Posted: Tue Oct 21, 2014 5:26 pm
by Klaus
Franco,
... I have about 200 lines...
then of course you need to use LINEOFFSET! 8)

Re: alphabetical order: highlight first row

Posted: Tue Oct 21, 2014 5:49 pm
by jmburnod
Klaus,
then of course you need to use LINEOFFSET!
No for this part, fld "fldOrdineAlfabetico" contains a list of items. A kind of index of the target list fld
The itemoffset return the num of the first line begining with a choose letter (the label of a btn)
Getting the vScroll of the field according the num of the found line is the next step and yes
we need lineoffset to do it
Best
Jean-Marc

Re: alphabetical order: highlight first row

Posted: Tue Oct 21, 2014 6:02 pm
by francof
jmburnod wrote: ....
Getting the vScroll of the field according the num of the found line is the next step and yes
we need lineoffset to do it
Best
Jean-Marc
ehm... this code:

Code: Select all

set the hilitedLine of fld "fldVitigni" to tNumRiga
scrolls the list field to the first line starting with the chosen letter, without using lineoffset

best
franco

Re: alphabetical order: highlight first row

Posted: Tue Oct 21, 2014 6:07 pm
by Klaus
Ah, sorry, I see, but using another itemlist seems a bit cumbersome to me 8)

Here a script that does what I think Franco needs.
Some hints:
1. "fld 1" is the field with your 200 lines
2. The field needs to be a LIST field
3. The script iis for your buttons and presumes that the buttons have the LABEL with the character you want to scroll to
Button name: whatever :-)
Button label: A or B or C etc...

Code: Select all

on mouseUp
  put the label of me into tSearchstring
  put lineOffset(return & tSearchstring, field 1) into tLine

  ## Character not in field, then exit handler!
  if tLine > 0 then
    exit mouseup
  end if

  ## Scroll to the founmd line
  set the scroll of field 1 to tLine * the effective textHeight of field 1

  ## Hilite that line_
  set the hilitedlines of fld 1 to tLine + 1
end mouseUp
Tested and works :D

Best

Klaus

Re: alphabetical order: highlight first row

Posted: Wed Oct 22, 2014 11:11 am
by francof
Klaus wrote: ...
Tested and works :D

Best

Klaus
I confirm.
What can I say, the Jean-Marc's solution made me work and this was a training for me. thanks to both

Klaus, just a little misprint in your script: I think you meant:

Code: Select all

if tLine =  0 then
  exit mouseup
end if
because, if there is no a line starting with the selected letter, tLine contains 0. and "if tLine > 0 then" always exit

A little problem with the first line (generally the "A" letter):
in my case, if the letter is "A" tLine contains 1 and when is added 1 to it the code shows me lines starting from the second line of the list.
so I've modified this:

Code: Select all

 ## Hilite that line_
   if tLine =  1 then put 0 into tLine
   set the hilitedlines of fld "fldVitigni" to tLine + 1
but why

Code: Select all

 put lineOffset(return & tSearchstring, fld "fldVitigni") into tLine
returns a number one less than the right one?
and, "effective textHeight" I did not understand what is it.
I've read on the dictionary something about the "...change the appearance of text in a field." and "Specifies the amount of space between lines of text in a field."

best
franco

Re: alphabetical order: highlight first row

Posted: Wed Oct 22, 2014 12:51 pm
by Klaus
Hi Franxo,

ha, you caught me! I just copied an old script of mine without thinking. :D

1. Yes, of coures it should read: if tLine = 0

2.
but why
CODE: SELECT ALL
put lineOffset(return & tSearchstring, fld "fldVitigni") into tLine
returns a number one less than the right one?
As you can see I added an EXTRA RETURN before the actuak text, so we have of course one line more in the result
which we need to take into account later!

Actually the extre return is an an old trick, but unfortunately I have forgotten what is is good for! :D

3.
"effective textHeight"
Check EFFECTIVE in the dictionary!

If you do not set a property for an object (like a textfont for fields) this object will inherit this property
from the next object in the object hierarchy.

Example:
Textfont of stack set to 12
You just create a new field aqnd do not set its textfont.
Now when you do: answer the textfon of fld 1
You will get empty, because the field does not have an explicit textfont.
But if you do: answer the EFECTIVE textfon of fld 1
You will get 12, because the addition of EFFECTIVE will also report the INHERITED property
and this is what we need here, just in case we did NOT set the textheight explicitely!

Get the picture?


Best

Klaus

Re: alphabetical order: highlight first row

Posted: Wed Oct 22, 2014 4:42 pm
by jacque
The extra return ensures that the match gets the letter at the start of the line and doesn't just match a letter in the middle of the first line it finds that contains it.

The script can be fixed like this:

Code: Select all

put lineOffset(return & tSearchstring, return & field 1) into tLine
Adding a return before the list content allows the first line to match.

Re: alphabetical order: highlight first row

Posted: Wed Oct 22, 2014 5:11 pm
by francof
Hi jacque,

thanks for the specification.
jacque wrote:The extra return ensures that the match gets the letter at the start of the line and doesn't just match a letter in the middle of the first line it finds that contains it.

The script can be fixed like this:

Code: Select all

put lineOffset(return & tSearchstring, return & field 1) into tLine
Adding a return before the list content allows the first line to match.
Klaus, do you understand? :) refresh your memory :) and thanks for your explanations.

ciao
franco

Re: alphabetical order: highlight first row

Posted: Wed Oct 22, 2014 9:24 pm
by Klaus
Ah, well, now, yes! :D

Merci Jaqueline!