OK, let's start a discussion - to keep an enhancement into collectionpropeditform.pas, like I did, or to create a new property editor, specially for TDBGridColumns collection?
In the current way I add a reference to DBGrids into collectionpropeditform.pas, because of access to the types I need. Also, add a new Acttion "actAddFields" in the action list and new separator and button into toolbar.
The new action and button are visible and enabled only if the collection type is TDBGridColumns.
When the user select this button, here is the method implementation:
procedure TCollectionPropertyEditorForm.actAddFieldsExecute(Sender: TObject);
var It : TCollectionItem;
flChanged : Boolean;
flEmpty : Boolean;
i : Integer;
begin
//
if Collection = nil then Exit;
if not ( Collection is TDBGridColumns ) then Exit;
flChanged := False;
flEmpty := False;
//Collection.Add;
//
//FillCollectionListBox;
//if CollectionListBox.Items.Count > 0 then
// CollectionListBox.ItemIndex := CollectionListBox.Items.Count - 1;
//SelectInObjectInspector(True, False);
//UpdateButtons;
//UpdateCaption;
//Modified;
if Collection.Count > 0 then
It := Collection.Items[ 0 ]
else begin
It := Collection.Add;
flEmpty:=True;
end;
if flEmpty or ( MessageDlg( fesFeTitle, oisConfirmDelete+oisAddFields+'?',
mtConfirmation, [mbYes, mbNo], 0) = mrYes ) then begin
try
if (It is TColumn) and ( Assigned( TDBGrid( TColumn( It ).Grid).DataSource ) ) and
Assigned ( TDBGrid( TColumn( It ).Grid).DataSource.DataSet ) then begin
flChanged:=True;
BeginFormUpdate;
Collection.Clear;
It := Collection.Add;
// TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Open;
if TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Fields.Count > 0 then begin
for i := 0 to TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Fields.Count - 1 do begin
if i > 0 then begin
It := Collection.Add;
end;
TColumn( It ).Field:=TDBGrid( TColumn( It ).Grid).DataSource.DataSet.Fields[ i ];
end;
end;
end;
finally
if flChanged then begin
RefreshPropertyValues;
UpdateButtons;
UpdateCaption;
Modified;
EndFormUpdate;
end
else
if flEmpty then begin
Collection.Clear;
RefreshPropertyValues;
UpdateButtons;
UpdateCaption;
Modified;
EndFormUpdate;
end;
end;
end;
end;