Question

I have implemented a TcxGrid with some columns. The cells in the last column in this grid contains buttons of type TcxEditButton.

The content of the grid is either entered by the user, or loaded from a textfile upon creating it's parent form.

I would like to hide some of these buttons based on a value in the grid. The value that determines the visibility of the buttons can either be read from the grids memory data set, or directly from a hidden column in the grid.

My problem is that I have not been able to find the correct event to do the check on the value, and set the buttons visibility property. I've tried to use all sort of events both on the grids table and the column that contains the buttons.

Any suggestions on how to get the button item and at the same time be able to set this when the grid is drawn?

Solution: Ended up using a modified version if the accepted solution.

procedure TFrame_cx_Element_Inntasting_Kriterier.cxGrid_InntastingDBTVPropertiesGetProperties(
  Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
  var AProperties: TcxCustomEditProperties);
begin
  if ARecord.Values[cxGrid_ColumnWithValidatedValue.Index] = true then
    AProperties := cxEditRepository1ButtonItem1.Properties
  else
    AProperties := cxEditRepository1Label1.Properties;
end;
Was it helpful?

Solution

Use the OnGetProperties event of the column with type TcxEditButton.

With the ARecord you can get the value of another column for the same row based on the column index.

The easiest way to set the properties is to use two predefinied TcxEditButtons in a TcxEditRepository, for example named ButtonsVisible and ButtonsInvisible.

The event would than look something like this:

procedure TForm1.cxGrid1TableView1EditButtonColumnGetProperties(
  Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
  var AProperties: TcxCustomEditProperties);
var
  Value: Variant;
  Buttons: TcxEditButtons;
  ButtonEnabled : Boolean;
begin
  if VarIsNull(ARecord.Values[cxGrid1TableView1ColumnToCheck.Index]) then
    AProperties := ButtonsInvisible.Properties; 
    // or AProperties := ButtonsVisible.Properties depending on what you want/need

  Value := ARecord.Values[cxGrid1TableView1ColumnToCheck.Index];
   if (Value = ValueWhenVisible) then
     AProperties := ButtonsVisible.Properties
   else
     AProperties := ButtonsInvisible.Properties;
end;

Hope this will get you on the right track.

OTHER TIPS

Use OnInitEdit Event on TcxGridDBTableView .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top