Page 1 of 1
Datagrid cell restrictions
Posted: Thu Jan 19, 2012 8:44 pm
by bsouthuk
Hi all
Could someone tell me if it is possible to restrict what a user can enter in a cell within a data grid. Basically there is 1 column in my table that a user must complete manually or by uploading a CSV.
However, in this column there must be no more than 11 numbers entered. I want an error message or some form of control that does not allow users to enter more than 11 numbers (or any text at all) and also will not allow a user to go to the 'next stage' if less than 11 characters are added (or text is added)
Help is greatly appreciated.
Re: Datagrid cell restrictions
Posted: Thu Jan 19, 2012 11:05 pm
by dunbarx
The datagrid is just a bunch of groups of ordinary LC objects, magically organized.
But the entry field is just that, a field called, I think, "dataGridFieldEditor", and generates "rawKeyDown", "keyDown" and other typical messages.
You can trap these and validate the data in any way you want. Limiting to 11 chars is a cakeWalk.
Craig Newman
Re: Datagrid cell restrictions
Posted: Thu Jan 19, 2012 11:27 pm
by bsouthuk
Thats great thanks Craig. I have the following code that works as wanted in a normal field:
Code: Select all
on keyDown theKey
if the length of me >= 10 then
## The maximum length has been reached
## keyDown is not passed so the key is not entered into the field
beep
else
## The maximum length has not been reached
## keyDown is passed and the key is entered into the field
pass keyDown
end if
end keyDown
I am just not sure where to put this code within the data grid...
Re: Datagrid cell restrictions
Posted: Fri Jan 20, 2012 12:25 am
by dunbarx
Its that magic thing.
If you create a new datagrid, all you get is a bunch of groups and graphics. If you create a column or two, you suddenly find yourself with a bunch of fields. If you place data in some of the cells, you get even more fields.
On a blank card, place a datagrid. Add a column or two. Put some data in the contents pane.
In the card script, or in the master group script of the dg, put
Code: Select all
on keydown
if the length of target > 11 then exit to top -- or whatever...
pass keydown
end keydown
Target is a temporary editable field (field "DataGridFieldEditor") that is ephemeral. The dg creates and locates it as needed, overlying the cell of interest, and losing it when it is finished. (This info is all thanks to Jacque (who else?))
Craig Newman
Re: Datagrid cell restrictions
Posted: Fri Jan 20, 2012 12:37 am
by bsouthuk
Aaaah now thats great, but what if the rule should only apply to 1 column named 'MobileNumber' for instance?
Re: Datagrid cell restrictions
Posted: Fri Jan 20, 2012 3:02 am
by dunbarx
I am not a DG expert. But I know there must be gadgets that will tell you what you need. This likely will go behind the back of the workaround I proposed.
Check out the large DG manual available from RR. The info is certainly there.
Craig Newman
Re: Datagrid cell restrictions
Posted: Fri Jan 20, 2012 12:12 pm
by bsouthuk
Thanks Craig for you help.
I have trawled through the manual and searched high and low on the web and I still can't work it out for the life of me.
Can anyone else shed any light on this?
Re: Datagrid cell restrictions
Posted: Sat Jan 03, 2015 10:19 am
by Simon Knight
Bump 3 years...... have passed,
Was an answer found ? I am trying to do similar with a datagrid.
Simon K