Advice on using edControlDropdown editor type

Hi,

I need to use a treeview as a cell editor, so I'm using
edControlDropDown and setting the control to my treeview component as
follows:

procedure TForm33.AdvGrid1GetEditorType(Sender: TObject; ACol, ARow: Integer; var AEditor: TEditorType);
begin
   AEditor:=edControlDropDown;
end;

procedure TForm33.AdvGrid1GetEditorProp(Sender: TObject; ACol, ARow: Integer; AEditLink: TEditLink);
begin
  AdvGrid1.ControlDropDown.Control:=Treeview1;
  Treeview1.Visible:=TRUE;
end;

As
the user selects nodes on the treeview, I want to update the cell
contents. I've tried adding an OnChange call to the treeview, as below,
but this doesn't update the cell! Can you tell me how I can achieve
this. I can't see any demo apps using edControlDropDown.

procedure TForm33.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
  AdvGrid1.Cells[AdvGrid1.Col,AdvGrid1.Row]:=Node.Text;
end;

Thanks in advance.

Please implement the grid.OnCellValidate() event and return the treeview selected node text via the var param Value of the event handler.

Have tried that, as below, but OnCellValidate doesn't get called, either when the user selects nodes or when the user exits the treeview
and the editing stops!

procedure TForm33.AdvGrid1CellValidate(Sender: TObject; ACol, ARow: Integer; var Value: string; var Valid: Boolean);
begin
  if Treeview1.Selected<>NIL then
  begin
    AdvGrid1.Cells[ACol,ARow]:=Treeview1.Selected.Text;
  end else
  begin
    AdvGrid1.Cells[ACol,ARow]:='';
  end;
end;

Sorry, pasted incorrect code above, should have been as below, but still doesn't work!

procedure TForm33.AdvGrid1CellValidate(Sender: TObject; ACol, ARow: Integer; var Value: string; var Valid: Boolean);
begin
  if Treeview1.Selected<>NIL then
  begin
    Value:=Treeview1.Selected.Text;
  end else
  begin
    Value:='';
  end;
end; 

Been examining your source code, and think I've answered my own question! In Treeview.OnChange method I need to do:

AdvGrid1.ControlDropdown.Text:=Node.Text;

rather than

AdvGrid1.Cells[AdvGrid1.Col,AdvGrid1.Row]:=Node.Text;

I'm getting close to what I need to achieve, but have a couple of issues.

1) When I click the cell, the control dropdown appears with the treeview, and I can click on nodes to select, and the cell contents change - all great! However, when I click off the treeview, although the control dropdown disappears, the cell is still in edit mode, and I can still type into the cell. How can I exit edit mode when I click off the treeview?

2) I'd like to be able to navigate the treeview with the Up/Down arrows, but the grid is getting these keypresses and stopping the edit and moving the active cell up/down instead. How can I get the treeview to process the keypresses, rather than the grid?

  1. You can assign an event handler to handle the DropUp and hide the inplace editor from there. See sample code below.
    2. This was currently not yet possible. We have added a property though so you will be able to enable this in the next update by setting grid.ControlDropDown.WantArrows := true.

    procedure TForm3.DropUp(Sender: TObject; Cancelled: boolean);
    begin
      advstringgrid1.HideInplaceEdit;
    end;

    procedure TForm3.FormCreate(Sender: TObject);
    begin
      advstringgrid1.DefaultEditor := edControlDropDown;
      advstringgrid1.ControlDropDown.Control := Treeview1;
      advstringgrid1.Options := advstringgrid1.Options + [goEditing];
      advstringgrid1.ControlDropDown.OnDropUp := DropUp;
      advstringgrid1.ControlDropdown.WantArrows := true;
    end;