Accesing text of a cell in table field by clicking on it
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 39
- Joined: Thu Jan 23, 2020 5:56 pm
Accesing text of a cell in table field by clicking on it
Hi,
I'm creating an app with a table. I need to create an option for clicking on the table's cells. couldn't find a way to do it instead of using al lot of buttons... Any idea?
thanks
I'm creating an app with a table. I need to create an option for clicking on the table's cells. couldn't find a way to do it instead of using al lot of buttons... Any idea?
thanks
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Accesing text of a cell in table field by clicking on it
Hi.
When you say "click on a table's cells", what do you mean? Are you talking about a table field, so you can edit the "cells" within?
Or are you creating your own table with a group of controls, perhaps buttons or fields?
In any case, once you write back, we can fix this in about a minute.
Craig
When you say "click on a table's cells", what do you mean? Are you talking about a table field, so you can edit the "cells" within?
Or are you creating your own table with a group of controls, perhaps buttons or fields?
In any case, once you write back, we can fix this in about a minute.
Craig
-
- Posts: 39
- Joined: Thu Jan 23, 2020 5:56 pm
Re: Accesing text of a cell in table field by clicking on it
Hi, thank you for your answer!
I am using table field and I don't want to edit the cells, I want to be able to "mouseDown" on each cell.
I am using table field and I don't want to edit the cells, I want to be able to "mouseDown" on each cell.
-
- VIP Livecode Opensource Backer
- Posts: 9802
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Accesing text of a cell in table field by clicking on it
See the field script in the attached example.
Note that in this script, being able to determine the cell within a given line (which will likely extend further than the text within the cell) requires that all tabstops be explicitly set. See the Dictionary entry for "tabstops" for a description of that field property.
Code: Select all
on mouseDown
-- Get clicked line:
put word 2 of the clickLine into tLine
-- Get clicked column:
put the clickH into tH
put 0 into tCell
repeat for each item tWidth in the tabstops of me
if tH < tWidth then exit repeat
add 1 to tCell
end repeat
-- Select the clicked text:
set the itemdel to tab
select item tCell of line tLine of me
-- Report details if needed:
put "Line="& tLine && "Item="& tCell && \
"Text="& the text of item tCell of line tLine of me \
into fld "Display"
end mouseDown
- Attachments
-
- ClickTable Example.zip
- (912 Bytes) Downloaded 175 times
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Accesing text of a cell in table field by clicking on it
OK.
So do you want the user to click somewhere, have a dialog come up, enter some data, and have that data fill the "cell" where the click was?
If so, table fields need to be hacked just a bit to do this. Table fields are tab and return delimited. Know that you can:
You could, in the field script(pseudo):
That last line requires you to know the tabStops and the text height. Just some simple math. Can you do it?
Craig
So do you want the user to click somewhere, have a dialog come up, enter some data, and have that data fill the "cell" where the click was?
If so, table fields need to be hacked just a bit to do this. Table fields are tab and return delimited. Know that you can:
Code: Select all
set the itemDel to tab
put "foo" into item 3 of line 2 of fld "yourtableField"
Code: Select all
on mouseDown
put the topLeft of me into XY
put the clickLoc into tLoc
ask "What?"
put it into temp
set the itemDel to tab
put temp into the item that corresponds to the distance from XY to tLoc
end mouseDown
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9802
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Accesing text of a cell in table field by clicking on it
Are my posts not visible here?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 39
- Joined: Thu Jan 23, 2020 5:56 pm
Re: Accesing text of a cell in table field by clicking on it
Thank you so much guys! Its working!!
-
- Posts: 39
- Joined: Thu Jan 23, 2020 5:56 pm
Re: Accesing text of a cell in table field by clicking on it
No, you helped me a lot!
Re: Accesing text of a cell in table field by clicking on it
I think it is just a case of timing, Richard.
-
- VIP Livecode Opensource Backer
- Posts: 9802
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Accesing text of a cell in table field by clicking on it
Thanks, BigGameOver. I've lost count of the number of times I've posted a solution here and the conversation keeps going like no one saw it. Glad this one helped.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Accesing text of a cell in table field by clicking on it
Is this like asking "Are you asleep?"Are my posts not visible here?
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Accesing text of a cell in table field by clicking on it
Hi again.
This works, if you do not already have it the way you want it. Make a table field and set its tabStops to "75,150,225,300,375,450,525,600"
Put this into the field script:
The only issue here is that a fresh table field has its tabStops set to "75". That is because LC interprets that single value as the same as "75,150,225,300..." So unless you manually set your own unique tabStops when you configure your field, you have to expand the default one. Otherwise the repeat loop will fail. Do you know what I mean?
Craig
This works, if you do not already have it the way you want it. Make a table field and set its tabStops to "75,150,225,300,375,450,525,600"
Put this into the field script:
Code: Select all
on mouseDown
put the textheight of me into tHeight
put item 1 of the clickLoc - item 1 of left of me into x
put item 2 of the clickLoc - item 1 of top of me into y
put y div theight into lineNum
if y mod tHeight <> 0 then add 1 to lineNum
repeat with z = 1 to the number of items of the tabStops of me
if item z of the tabstops of me > x then
put z into itemNum
exit repeat
end if
end repeat
ask "What?"
set the itemDel to tab
put it into item itemNum of line lineNum of me
end mouseDown
Craig
Last edited by dunbarx on Thu Jan 23, 2020 9:23 pm, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 9802
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Accesing text of a cell in table field by clicking on it
Not quite. Subsequent posts seem unlikely to have been written while asleep.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Accesing text of a cell in table field by clicking on it
@Richard.
I do my best work asleep.
@BigameOver
We can avoid the tabStop issue by simply analyzing the current setting. If a single value, expand to infinity as I mentioned above. If explicit, it may be that the last value is not great enough. This is because LC will take the width of the last tab and extend that to infinity. So shall we.
This can be added as a small routine to the field itself, so that if you change its form, the handler will still run just fine.
Craig
I do my best work asleep.
@BigameOver
We can avoid the tabStop issue by simply analyzing the current setting. If a single value, expand to infinity as I mentioned above. If explicit, it may be that the last value is not great enough. This is because LC will take the width of the last tab and extend that to infinity. So shall we.
This can be added as a small routine to the field itself, so that if you change its form, the handler will still run just fine.
Craig
-
- Posts: 39
- Joined: Thu Jan 23, 2020 5:56 pm
Re: Accesing text of a cell in table field by clicking on it
@dunbarx
thanks!
I set the tabStops manually and its working fine
thanks!
I set the tabStops manually and its working fine