Recent

Author Topic: dbGrid how-to edit column Title and Width  (Read 20215 times)

Anonymous

  • Guest
dbGrid how-to edit column Title and Width
« on: June 11, 2005, 02:09:33 pm »
i can'not find..
can change Title and Widht and Fields of dbGrid in manual code

Thanks
Fernando

matthijs

  • Hero Member
  • *****
  • Posts: 537
dbGrid how-to edit column Title and Width
« Reply #1 on: June 11, 2005, 03:17:00 pm »
You can access them through the columns property of the DBGrid.
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.) :)

:( Why cannot I upload my own Avatar? :(

jtiedeman

  • New member
  • *
  • Posts: 8
Re: dbGrid how-to edit column Title and Width
« Reply #2 on: December 31, 2008, 01:04:24 am »
The only Column property I can find for TDBGrid is under Headings and apparently seems only to let us add one at a time. No size or attachment to any particular field in the data source.

jesusr

  • Sr. Member
  • ****
  • Posts: 484
Re: dbGrid how-to edit column Title and Width
« Reply #3 on: December 31, 2008, 07:50:25 am »
drop a dbgrid on a form, make sure it's selected, press F11, this will bring Object Inspector to front, look for "columns" property, select the row for this property, there should appear a [...] button at the right, click it, this will bring Columns editor to front, now you can add columns to dbgrid, for each item you add a column will appear in dbgrid, selecting each item (column) will make object inspector to show its properties one of such properties it's "Fieldname", another it's "Title" which is expandable, once expanded there should be a "Caption" property which controls the title that appears in column.

tatamata

  • Hero Member
  • *****
  • Posts: 787
    • ZMSQL - SQL enhanced in-memory database
Re: dbGrid how-to edit column Title and Width
« Reply #4 on: January 01, 2009, 06:21:16 pm »
Also, you can auto adjust columns to their contents (I think it is AutoAdjust procedure. Ther is also AutoFill property...
You can also adjust columns to Title text width, by using this or similar procedure:

procedure TFormMain.AdjustDBGridColumnsToTitles(var pDBGrid:TDBGrid);

var

  vTitleWidth:Integer;

  vTextWidth:Integer;

  I:Integer;

begin

  with pDBGrid do begin

    //Adjust columns to titles width.

    for I:=0 to Columns.Count-1 do begin

      vTitleWidth:=Canvas.TextWidth(Columns.Title.Caption);

      vTextWidth:=Columns.Width;

      if(vTitleWidth>vTextWidth) then

        begin

          Columns.Width:=vTitleWidth+10;

        end;

    end;

  end;

end;

 

TinyPortal © 2005-2018