3

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;
Øystein
  • 1,163
  • 1
  • 12
  • 23

2 Answers2

4

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.

evdkraan
  • 171
  • 1
  • 4
  • Yes using this event did get me on the right track. I ended up having to define a csEditRepository. Add two styles to it. One for the state where the button should be invisible, and one for the state where it should be visible. I will post the code for reference – Øystein May 02 '12 at 08:52
  • I get Undeclared identifier "TcxCustomEditProperties". Can you please tell me which library i need to include? – Tone Škoda Aug 09 '17 at 09:48
0

Use OnInitEdit Event on TcxGridDBTableView .

MajidTaheri
  • 3,813
  • 6
  • 28
  • 46
  • I believe oninitedit is triggered just before the cell is going into edit mode. This is not what i need i think. I need an event that is called everytime all the cells in the column are drawn, and where i can read data from cells in the current row (row index or directly from the mem dataset) and where i also are able to get the actual button item (not the cell, but the content of the cell). – Øystein Apr 27 '12 at 18:27