Board index » delphi » Run time change of dbGrid (Delphi 2)

Run time change of dbGrid (Delphi 2)

When you put your grid on the form and attach it to the datasource, don't
manually add any fields in the column editor.

In your code, you need to add these lines:

(Assuming that you have fields called LastName and FirstName in your table)

DBGrid1.Columns.Add;
DBGrid1.Columns[0].FieldName:='LastName';
DBGrid1.Columns[0].Title.Caption:='Last Name';
DBGrid1.Columns[1].FieldName:='FirstName';
DBGrid1.Columns[1].Title.Caption:='First Name';

You can add as many fields as you want. The Title.Caption line is optional
if you don't mind the title being the same as the field name.
-------------------------------------------
Matthew J. Brock
Computer Solutions:AZ
Tucson, AZ - Home of the 1997 National Basketball Champion Wildcats!

TVisualBasic=class(None);

A.J.M. van den Berg <ajmb...@worldaccess.nl> wrote in article
<3378d788.1256...@news3.worldaccess.nl>...
: Hi,
:
: I'm creating a small database program which has a dbgrid component to
: display the data. On the form I have also placed a tabset component.
: What I want to do is to display a different set of fields in the
: dbgrid component depending on the chosen tab of the tabset component.
:
: The problem is that I don't really understand how to change run-time
: the fields displayed in the dbgrid component. A small example or some
: hints would be very helpfull.
:
: Thank you for your reaction!
:
: Regards, Ap
:

 

Re:Run time change of dbGrid (Delphi 2)


A.J.M. van den Berg wrote:

Quote

> Hi,

> I'm creating a small database program which has a dbgrid component to
> display the data. On the form I have also placed a tabset component.
> What I want to do is to display a different set of fields in the
> dbgrid component depending on the chosen tab of the tabset component.

> The problem is that I don't really understand how to change run-time
> the fields displayed in the dbgrid component. A small example or some
> hints would be very helpfull.

> Thank you for your reaction!

> Regards, Ap

hello

to change dbgrid's display name you have to do as followings.

dbgrid1.fields[0].displaylabel:='xxxxxxxx';

i hope this helps you.

sang-hong
--
????????????????????????????

 ???? : (?) ?a? (Company : Daou Technology)  
 o??-? : USS ???o?    (Dept. : USS)                
 ?  : 82-2-3450-4841                              
 Fax : 82-2-538-1895                                
 mailto:sh...@daou.co.kr

????????????????????????????

Re:Run time change of dbGrid (Delphi 2)


use the TField.index property.

HTH,

--
Paul Motyer
Soft Stuff, Croydon, Australia, 3136

A.J.M. van den Berg <ajmb...@worldaccess.nl> wrote in article
<3378d788.1256...@news3.worldaccess.nl>...

Quote
> Hi,

> I'm creating a small database program which has a dbgrid component to
> display the data. On the form I have also placed a tabset component.
> What I want to do is to display a different set of fields in the
> dbgrid component depending on the chosen tab of the tabset component.

> The problem is that I don't really understand how to change run-time
> the fields displayed in the dbgrid component. A small example or some
> hints would be very helpfull.

> Thank you for your reaction!

> Regards, Ap

Other Threads