Blocking copy / Ctrl+C in a grid

I’ve hear that this request is often asked.

So there is a little piece of code to block all copy of data in a grid (for all form)

If you want to do this only on one form, you need to overwritte the method taks in the form

 

For my case, you need to select the method “task” on the class “SysSetupFormRun’ and write this:

FormControl form;
//standard code
if (_p1 == #taskCopy)
{
    form = this.control(this.selectedControl().containerId());
    if (form && form.handle() == classNum(FormGridControl))
    {
        //warning('Cannot copy on this grid!');
        return 0;
    }
}
ret = super(_p1);
return ret;

And for disable the copy on a specific field :

In the code I use this : this.selectedControl().containerId()
The method selectedControl return the fields on which we are, so you need simply use this : (with ItemName as fieldName from SalesTable form)

   if (_p1 == #taskCopy)
   {
       form = this.selectedControl();
       if (form.name() == 'ItemName')
       {
           //warning('Cannot copy this field!');
           return 0;
       }
   }

My original post : http://blogs.msdn.com/b/sebastien-petre/archive/2013/02/21/blocking-copy-ctrl-c-on-a-grid.aspx

Advertisements