Jump to content

how to disable row cells in UniDBGrid


jeffswanberg

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 comment
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 comment
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 comment
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 comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...