Jump to content

how to disable row cells in UniDBGrid


Recommended Posts

Assuming I have a unidbgrid with five columns attached to a data set. How do I disable the editing on columns 1, 2 and 3 when the value of the fifth column is 1 but they are editable if the value in the fifth column is anything else?

And, in which event would this be best suited?

 

Jeff

Link to post
Share on other sites

Hi,

 

You can use, DataSource->onDataChange event,

for example:

procedure TMainForm.DataSource1DataChange(Sender: TObject; Field: TField);
begin
  if (Sender as TDataSource).DataSet.Fields[3].AsInteger = 1 then
  begin
    (Sender as TDataSource).DataSet.Fields[3].ReadOnly := True
  end
  else
  begin
    (Sender as TDataSource).DataSet.Fields[3].ReadOnly := False
  end;
end;

Best regards.

Link to post
Share on other sites
  • 1 year later...

Is it possible to set one cell to ReadOnly = True/False?

 

for example,

Row 1 -> if the 1st column's value is Y, then the 2nd column is "ReadOnly = True" (cannot edit)

Row 2 -> the 1st column's value is N, then the 2nd column is "ReadOnly = False" (can edit)

Link to post
Share on other sites

Thanks for your reply.

 

 

ColA is CheckBox

             ColA  |  ColB
Row1    True     Success     (Row1 - ColA ReadOnly Is False)
Row2    False     Fail           (Row2 - ColA ReadOnly Is True)
Row3    False    Fail            (Row3 - ColA ReadOnly Is True)
Row4    False    Success    (Row4 - ColA ReadOnly Is False)

It means user can only edit the ColA of Row1 & Row4.

 

 

function beforeedit(editor, context, eOpts)
{
    var me=context;
    if ((me.column.dataIndex == "0") && (me.record.data[1] != "Success")) {
        return false;
    }
}

 

I use the above code, but Row 2 & Row 3 (ColA) still can be edited. Anything is wrong?

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...