Data Entry with a DataGrid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Data Entry with a DataGrid
I am attempting a data entry app using a DataGrid. I have run into a wall and am hoping that it is just inexperience and not a bug. I have scanned the forums and the web to no avail so I am now asking the experts. I have built a tiny example that demonstrates my technique and the problem. First the criteria: I need a program for data entry by expert data entry people that only use the keyboard. So the idea is they start a new line and tab to each subsequent field and at the end of a line start the next record. I have a perfect version demonstrating 3 fields. I insert a blank line on openCard and then you can tab through the one empty line as expected. if you change the first field (I use a date just to indicate there is something in the field) or type anything at all in the other two fields I insert another blank line which will be tabbed into at the end of the first line. This behavior will continue forever perfectly. The problem occurs in the second example which attempts to insert a checkbox into the second column. I have to adjust the OpenNextFieldEditor handler to get the focus to go where I want it as well as the tabKey handler (which is not needed in the simple version but closeFieldEditor is not called for buttons). Now everything works perfectly until you reach the n+1th record in an n line DataGrid. I have had to use a rollover routine to adjust the index to be between 1 and the number of lines visible in the DataGrid as I attempt to set the focus to the checkbox. It works for the first 6 (of a 6 line DataGrid) and then on the seventh it will set the focus to line 6 instead of line 1 (which is actually the 7th line). If I try a RefreshList call after the Addline call it gets worse with it backtracking the focused line of the checkbox a variable number of lines instead of just one. If I call ResetList after the insert although it resets the focus to the top of the DataGrid it behaves when it gets down to the end of the list but I obviously cannot have it reset to the top each time. I have tried everything I can think of to no avail. Please if this is possible please show me the way and if not I need to know that too.
Re: Data Entry with a DataGrid
The forum didn't attach my files. I'm trying again but it failed telling me the extensions "livecode" and "rev" are not allowed so I'll have to kill the extensions. They are in fact livecode stacks.
Re: Data Entry with a DataGrid
Still no files attached. Now it tells me the extension is not allowed and they didn't have any. I suspect it won't let me attach a file no matter what the extension is due to my low post count. Please PM me and I'll email them. They are only about 20KB each.
Re: Data Entry with a DataGrid
Hi thims,
1. welcome to the forum!
2. a. You need to have a t least 10 postings before you can add attachments and post URLs.
b. You cannot post "pure" REV or LIVECODE stack as you experienced, you need to ZIP them before posting.
3. Adding some empty lines and paragraphs will make your posting(s) much more readable!
Will copy it to a text editor and try to get what you are after
But be aware, DataGrids are the most complex Livecode objects EVER!
Best
Klaus
1. welcome to the forum!

2. a. You need to have a t least 10 postings before you can add attachments and post URLs.
b. You cannot post "pure" REV or LIVECODE stack as you experienced, you need to ZIP them before posting.
3. Adding some empty lines and paragraphs will make your posting(s) much more readable!
Will copy it to a text editor and try to get what you are after

But be aware, DataGrids are the most complex Livecode objects EVER!
Best
Klaus
Re: Data Entry with a DataGrid
Given the complexity of the DataGrid, especially when trying to coax special behavior... you might consider just using a set of fields to accept the data entry and then just add the line of data to the bottom of the dataGrid.
Code: Select all
temp = fld "one" & tab & fld "two" & tab & fld "three"
dispatch "AddLine" to grp "myGrid" with temp
Re: Data Entry with a DataGrid
Unfortunately that is not an option for keyboard only input.
I do use AddLine to add "tab & tab & tab & cr" to the DataGrid then then EditCellOfIndex to edit the line. All good until the n+1th line when sending focus to the checkbox goes to the wrong line. I'm trying to find relevant things to say on other forum posts to rack up 10 posts so I can post my code.
Just a DataGrid and a few lines of code demonstrate this problem.
I do use AddLine to add "tab & tab & tab & cr" to the DataGrid then then EditCellOfIndex to edit the line. All good until the n+1th line when sending focus to the checkbox goes to the wrong line. I'm trying to find relevant things to say on other forum posts to rack up 10 posts so I can post my code.
Just a DataGrid and a few lines of code demonstrate this problem.
Re: Data Entry with a DataGrid
OK, Here's the code. Please someone have a quick look. Just a DataGrid and a tiny bit of code to facilitate data entry by keyboard ... and the checkbox version that loses it's place on line 7. The problem occurs when tabbing from line 6 to the newly created line 7 and then to the checkbox. So my testing sequence has been to double click into Col 1 then tab,tab,"a",tab,tab,tab,"b",tab,tab,tab,"c",tab,tab,tab,"d",tab,tab,tab,"e",tab,tab,tab,"f",tab,tab .. and BAM the wrong checkbox is hilited.
- Attachments
-
- MinimumDataEntry.zip
- (10.97 KiB) Downloaded 316 times
Re: Data Entry with a DataGrid
Hi thims,
1. please always give your stacks a NAME and not only a filename!
There are now 2 stacks named "untitled 1" in your ZIP archive and again LC complains heavily when opening both files at once!
2. Can you please give us a recipe how and what to test for?
I click the checkbox and a new line appears, and now?
Sorry, dont get it...
Best
Klaus
1. please always give your stacks a NAME and not only a filename!
There are now 2 stacks named "untitled 1" in your ZIP archive and again LC complains heavily when opening both files at once!

2. Can you please give us a recipe how and what to test for?
I click the checkbox and a new line appears, and now?
Sorry, dont get it...
Best
Klaus
Re: Data Entry with a DataGrid
Hi thims:
Unfortunately, I couldn't examine you stack since I am still using LC 6.7 (waiting for a stable LC 8 to make the jump!). However, my comments may be helpful in resolving the issue.
1. EditCellOfIndex works only with fields (through EditValue and EditFieldText). It fails (in my tests) while going to non-field cells such as a menu, picture, or checkbox.
Your comments
But, at another place, you seem to imply that you use EditCellOfIndex for each line, not just after the last line.
2. Aside, can you tell me how you get the code to "focus" on the cell containing checkbox? Tabbing doesn't go to a non-field cell; the focus moves to the data grid object and then other objects on the card.
Regards,
Sri
Unfortunately, I couldn't examine you stack since I am still using LC 6.7 (waiting for a stable LC 8 to make the jump!). However, my comments may be helpful in resolving the issue.
1. EditCellOfIndex works only with fields (through EditValue and EditFieldText). It fails (in my tests) while going to non-field cells such as a menu, picture, or checkbox.
Your comments
...I insert another blank line which will be tabbed into at the end of the first line....
imply that you don't use EditCellOfIndex until you get to the end of the table. Now, EditCellOfIndex won't work if you try to go to the checkbox of line 1, as you seem to do....All good until the n+1th line when sending focus to the checkbox goes to the wrong line....
But, at another place, you seem to imply that you use EditCellOfIndex for each line, not just after the last line.
If so, then I have to assume that you are not using EditCellOfIndex to go directly to the checkbox (or else, it wouldn't have worked on any line).I do use AddLine to add "tab & tab & tab & cr" to the DataGrid then then EditCellOfIndex to edit the line.
2. Aside, can you tell me how you get the code to "focus" on the cell containing checkbox? Tabbing doesn't go to a non-field cell; the focus moves to the data grid object and then other objects on the card.
Regards,
Sri
Re: Data Entry with a DataGrid
Thanks for the help so far. I have named the stacks on my 2nd try and saved them as 5.5 and tested it on my 6.1.3 box, everything is the same.
Here is my testing sequence of keystrokes:
double click into Col 1 then tab,tab,"a",tab,tab,tab,"b",tab,tab,tab,"c",tab,tab,tab,"d",tab,tab,tab,"e",tab,tab,tab,"f",tab,tab .. and BAM the wrong checkbox is hilited.
I never press the space bar to "click" the checkbox just tab past it but if I do, it just adds the new line earlier than when I type something into Col 3 which is where the letters "a", "b" etc are being typed in before a tab adds the new line and sends the cursor to the next (new) line.
The idea is to never touch a mouse while doing data entry.
I have tried a few more things:
If I pass OpenNextFieldEditor pDirection I never focus on the checkbox at all, just back and forth between the two fields, although it accepts data and moves forward as though the checkbox isn't there.
Is my "focus on btn" line incorrect and failing silently?
if I pass tabKey I now focus on the checkbox but then tab to dgEventCatcher of the DataGrid from there and that is where I am stopped.
If I pass neither I get the previous behavior where it works fine until the n+1th line.
One last clue: If I execute ResetList after I add a line, it resets my cursor to the top of the DataGrid each time but after n lines if I comment out the ResetList it continues to execute perfectly until the (2n)+1th line and will do the same on the (3n)+1th line etc. It seems so close to perfect.
Here is my testing sequence of keystrokes:
double click into Col 1 then tab,tab,"a",tab,tab,tab,"b",tab,tab,tab,"c",tab,tab,tab,"d",tab,tab,tab,"e",tab,tab,tab,"f",tab,tab .. and BAM the wrong checkbox is hilited.
I never press the space bar to "click" the checkbox just tab past it but if I do, it just adds the new line earlier than when I type something into Col 3 which is where the letters "a", "b" etc are being typed in before a tab adds the new line and sends the cursor to the next (new) line.
The idea is to never touch a mouse while doing data entry.
I have tried a few more things:
If I pass OpenNextFieldEditor pDirection I never focus on the checkbox at all, just back and forth between the two fields, although it accepts data and moves forward as though the checkbox isn't there.
Is my "focus on btn" line incorrect and failing silently?
if I pass tabKey I now focus on the checkbox but then tab to dgEventCatcher of the DataGrid from there and that is where I am stopped.
If I pass neither I get the previous behavior where it works fine until the n+1th line.
One last clue: If I execute ResetList after I add a line, it resets my cursor to the top of the DataGrid each time but after n lines if I comment out the ResetList it continues to execute perfectly until the (2n)+1th line and will do the same on the (3n)+1th line etc. It seems so close to perfect.
- Attachments
-
- MinimumDataEntry2ndTry.zip
- (11.42 KiB) Downloaded 311 times
Re: Data Entry with a DataGrid
Sorry, still don't get it!?

Please see the attached screenshot, I made your tapping exercise above and no checkbox checked! What am I missing?thims wrote:double click into Col 1 then tab,tab,"a",tab,tab,tab,"b",tab,tab,tab,"c",tab,tab,tab,"d",tab,tab,tab,"e",tab,tab,tab,"f",tab,tab .. and BAM the wrong checkbox is hilited.
Re: Data Entry with a DataGrid
Klaus;
Thanks so much for looking. I didn't know you were on a Mac so I tried it on mine and I see where the confusion is. On my Win 7 machine the check boxes are hilited when they have the focus. By that I do not mean checked but a red dotted line around the text "New button" indicating the checkbox has the focus. At that point if you hit the spacebar it will either check or uncheck the checkbox. I'm sorry to be so confusing but LiveCode uses the term hilited in code to indicate a true value for the checkbox whereas I am using the term to indicate a checkbox that has a visual indication that the checkbox has the focus, whether checked or not.
In the absence of any visual indication that the checkbox has the focus on my Mac, I tried a slightly different sequence to show the problem. the same as before but you are going to try and check the 7th checkbox Try:
double click into Col 1 then tab,tab,"a",tab,tab,tab,"b",tab,tab,tab,"c",tab,tab,tab,"d",tab,tab,tab,"e",tab,tab,tab,"f",tab,tab, "spacebar" should check the checkbox for line 7 that would then get the letter "g" but line 6 ("f") is the line that checks it's checkbox.
I am so sorry this is so hard to explain for such a simple example.
The idea is to keep inserting down the grid until the grid automatically moves all the lines up one to make the next line visible. That is when the DataGrid seems to get confused as to which line it is on. When I use the plug-in ReporttheFocusedObject it shows that the system thinks it is on the correct line but the previous line checks/unchecks it's checkbox.
Clear as mud! Sorry if I am being overly verbose but I am trying to convey the symptom as clearly as I can.
Thanks so much for looking. I didn't know you were on a Mac so I tried it on mine and I see where the confusion is. On my Win 7 machine the check boxes are hilited when they have the focus. By that I do not mean checked but a red dotted line around the text "New button" indicating the checkbox has the focus. At that point if you hit the spacebar it will either check or uncheck the checkbox. I'm sorry to be so confusing but LiveCode uses the term hilited in code to indicate a true value for the checkbox whereas I am using the term to indicate a checkbox that has a visual indication that the checkbox has the focus, whether checked or not.
In the absence of any visual indication that the checkbox has the focus on my Mac, I tried a slightly different sequence to show the problem. the same as before but you are going to try and check the 7th checkbox Try:
double click into Col 1 then tab,tab,"a",tab,tab,tab,"b",tab,tab,tab,"c",tab,tab,tab,"d",tab,tab,tab,"e",tab,tab,tab,"f",tab,tab, "spacebar" should check the checkbox for line 7 that would then get the letter "g" but line 6 ("f") is the line that checks it's checkbox.
I am so sorry this is so hard to explain for such a simple example.
The idea is to keep inserting down the grid until the grid automatically moves all the lines up one to make the next line visible. That is when the DataGrid seems to get confused as to which line it is on. When I use the plug-in ReporttheFocusedObject it shows that the system thinks it is on the correct line but the previous line checks/unchecks it's checkbox.
Clear as mud! Sorry if I am being overly verbose but I am trying to convey the symptom as clearly as I can.
Re: Data Entry with a DataGrid
Well this is a little disheartening. I was attempting to make my simple little example easier to understand on a Mac. First I added a red hilite border to Col 2 so you can see when it has focus on a Mac. Works in Win 7 but not OSX 10.10.2. Darn. So I tried skinning the buttons. A little sketchy as the Armed Icon acts sort of like a focus indicator but I don't have an Armed and hilited as opposed to Armed and not hilited. So it always looks unhilited when focused just in red. The other problem is the icon does not change until you leave the field as opposed to a default checkbox which changes its icon as soon as you press the spacebar. Anyway, all for not as the Armed Icon does not show up on the Mac either. I did put what would be the Armed and hilited icon in the Hover Icon just to see if it worked and that did work on the Mac it is just no use to me. Alas, a problem for another day, for now I cannot seem to give any kind of visual indication of a checkbox with focus on a Mac. I have attached the latest attempt with both the hilite border and the icons here in 7.10 format if anybody cares to witness nothing working as far as visual indication of a checkbox with focus on a Mac. Try it on a PC and it lights up like an Xmas tree.
- Attachments
-
- MinimumDataEntry3rdTry.zip
- (7.47 KiB) Downloaded 315 times
Re: Data Entry with a DataGrid
The property that controls this is the "showFocusBorder" of the control. On Windows it is active for buttons, but on Mac it is almost never active (it is active for fields on Mac though.) OS X has a system setting that allows keyboard interaction with buttons, but I can't remember if LC displays any visual differences even if that is set. Most users never set it.thims wrote:LiveCode uses the term hilited in code to indicate a true value for the checkbox whereas I am using the term to indicate a checkbox that has a visual indication that the checkbox has the focus, whether checked or not.
The ability to set a checkbox using the spacebar is also a Windows convention. If you want that to work on Mac, you'll need to track the focusedObject and the keyDown message and set the hilite via script. However, if the user doesn't have the OS set up to focus on buttons then I don't see a way to to do what you want on a Mac. The good news is that very few Mac users expect it.
One workaround would be to use small, square, locked fields instead of checkbox buttons. You can tab-focus on those on any OS. The field script can trap keyDown and if the key is the spacebar then it can set the imageSource of the field to an image of a checkmark. Put empty into the field to "uncheck" the box. Since you have a bunch of these, assign the script as a behavior to each "checkbox" field.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Data Entry with a DataGrid
Thanks for the excellent tip Jacque. I guess i'll try "rolling my own" checkboxes. They have certainly been a headache inside a DataGrid and I have custom comboboxes already.
My Mac certainly sets/clears a checkbox when pressing the spacebar there is just no visual cue that the checkbox in question has the focus. I guess Mac people don't use their keyboard much. In my world I get cursed out if my users have to take their hands off the keyboard for anything.
Kind of an interesting dividing point between Mac people and PC people. Mac people want to use their mouse for everything and PC people want to use their keyboard for everything. That makes sense to me somehow.
My Mac certainly sets/clears a checkbox when pressing the spacebar there is just no visual cue that the checkbox in question has the focus. I guess Mac people don't use their keyboard much. In my world I get cursed out if my users have to take their hands off the keyboard for anything.
Kind of an interesting dividing point between Mac people and PC people. Mac people want to use their mouse for everything and PC people want to use their keyboard for everything. That makes sense to me somehow.