Datagrid cell restrictions

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Datagrid cell restrictions

Post by bsouthuk » Thu Jan 19, 2012 8:44 pm

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Datagrid cell restrictions

Post by dunbarx » Thu Jan 19, 2012 11:05 pm

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

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: Datagrid cell restrictions

Post by bsouthuk » Thu Jan 19, 2012 11:27 pm

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...

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Datagrid cell restrictions

Post by dunbarx » Fri Jan 20, 2012 12:25 am

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

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: Datagrid cell restrictions

Post by bsouthuk » Fri Jan 20, 2012 12:37 am

Aaaah now thats great, but what if the rule should only apply to 1 column named 'MobileNumber' for instance?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Datagrid cell restrictions

Post by dunbarx » Fri Jan 20, 2012 3:02 am

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

bsouthuk
Posts: 261
Joined: Fri Dec 05, 2008 7:25 pm

Re: Datagrid cell restrictions

Post by bsouthuk » Fri Jan 20, 2012 12:12 pm

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?

Simon Knight
Posts: 919
Joined: Wed Nov 04, 2009 11:41 am

Re: Datagrid cell restrictions

Post by Simon Knight » Sat Jan 03, 2015 10:19 am

Bump 3 years...... have passed,

Was an answer found ? I am trying to do similar with a datagrid.

Simon K
best wishes
Skids

Post Reply