Re: Add field to ADOTable and a Column for a tDbGrid at runtime



Is your DBGrid Datasource pointing to the TADOTable and the TADOTable
pointing to the connection? Also is the DBGrid.Active = True?
If all this is setup, and you refresh the DBGrid, the grid will
repopulate with the new column. However, if you have columns coded or
in the control, this may be a problem.
Pablo Romero wrote:
Hi Fellas:

I have a little problem.

I need to add a field to a MS SQL Table at run-rime.

I did

ADOtable.close;
ADOCommand.CommandText := 'ALTER TABLE Empleados ADD COLUMN Notas
TEXT(25)';
ADOCommand.Execute;
ADOTable.Open;

Ok, the field is added.

Now i want to use that field in my program. So I Did:

with ADOTable do
begin
Close;

FieldDefs.Update;

for i := 0 to FieldDefs.Count - 1 do

if FindField(FieldDefs[i].Name) = nil then

FieldDefs.Items[i].CreateField(ADOMyTable);

F := TStringField.Create(ADOMyTable);
F.FieldName := 'myField';
F.DisplayLabel := 'myFieldLabel';
F.name := 'ADOmyNewField';
F.DataSet := ADOMyTable;
F.Size := 30;
Fields.Add(F);
open;
end;

Ok, the field is created.

Now I want to add this field to a column for a TDbgrid that is shown at this
time

The grid is showing the 3 fields that my ADOTABLE has. I added a 4th.

When I add the field to the Dbgrid using the 'tcolumn' object and the 'add'
method, the grid changes and shows one column, the lastest, the new.

Any ideas, please?

Regards.

Pablo Romero

.



Relevant Pages

  • Flackerndes Flat-Style im DBGrid
    ... Dazu habe ich ein Grid vom DBGrid abgeleitet und DrawCell überschrieben. ... Grid mache flackert das Grid. ... Es flackert nur bei den Linien der Fixed Cols ... kein Event-Handler hinter dem Doppelklick Event. ...
    (de.comp.lang.delphi.misc)
  • Re: Get back to a record
    ... When I get back to the Grid, it scrolls a bit and I didn't ... I am working on on a global variable which is known also to the DBGrid form ... > The bookmark should go to the same, and maybe you should try to get ...
    (comp.lang.pascal.delphi.misc)
  • dbgrid - move to new record
    ... I have a dbgrid on a form. ... records in the grid FIRST from a blank grid, and then click a command button ... on the form to enter ALL the records into the data source by using a loop. ... When I tab between columns, the data in the column is highlighted first, ...
    (microsoft.public.vb.controls)
  • Some DbGrid that shows also half rows
    ... I am looking for a DbGrid behaviour where the grid would show also ... so the upper part of a grid row. ... she had needed to do was to scroll down the TDbGrid on screen. ...
    (borland.public.delphi.thirdpartytools.general)
  • DBgrid and Mouse Wheel
    ... >Does anybody know how to make a dbgrid scroll up and down when>the ... >Fix it properly by subclassing a new DB grid and adding this fix, ... >TDBGridFix as your DBGrid. ... The fix belongs in the grid />grid ...
    (comp.lang.pascal.delphi.misc)