Hiding TcxEditButton for some rows in TcxGrid

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

The contents of the grid are either entered by the user or loaded from a text file when creating its parent form.

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

My problem is that I could not find the correct event to check the value and set the button visibility property. I tried to use all kinds of events both in the grid table and in the column containing the buttons.

Any suggestions on how to get the button element and at the same time be able to set this when drawing the grid?

Solution: Completed using a modified version if a decision is made.

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;
+3
source share
2 answers

Use the OnGetProperties event for a column of type TcxEditButton.

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

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

The event will 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 helps you on the right track.

+4
source

Use the OnInitEdit event in the TcxGridDBTableView.

0
source

All Articles