Board index » delphi » Adding New DBGrid Column at Runtime???

Adding New DBGrid Column at Runtime???

I'm trying to add a new DBGrid column at runtime by calling the Add method
like this:

DBGrid.Columns.Add

The result is all the original columns are removed from the grid, and a new
column without a title is added.  Subsequent calls to the same Add method
result in new columns.

Question:  How do I add a new column without clearing the original columns?

Thanks,
Lito

Lito Dizon
adi...@us.net

 

Re:Adding New DBGrid Column at Runtime???


Quote
On Sun, 8 Dec 96 08:17:48 EST, <adi...@mail.us.net> wrote:
>I'm trying to add a new DBGrid column at runtime by calling the Add method
>like this:

>DBGrid.Columns.Add

>The result is all the original columns are removed from the grid, and a new
>column without a title is added.  Subsequent calls to the same Add method
>result in new columns.

>Question:  How do I add a new column without clearing the original columns?

>Thanks,
>Lito

Lito,
        Since you're using a DBGrid and not a string grid, I assume you
want to display another data field in the grid. I always add all the
fields in the table (by double-clicking on the table object) and then
I make visible only those fields I want to display. In that way, I can
simple make a field visible to add a column displaying that field.
        ... or I could be completely misinterpreting your question! :-)
Good luck!

===========================================================
 Dan Gilbert                           dgpc...@{*word*104}ia.com
             www.interlink-2000.com/dgpc001
     Wait! Don't pick up that ph*)0z^%.NO CARRIER
===========================================================

Re:Adding New DBGrid Column at Runtime???


On Sun, 08 Dec 1996 21:58:49 GMT,
Dan Gilbert  <dgpc...@{*word*104}ia.com> wrote:

Quote
>        Since you're using a DBGrid and not a string grid, I assume you
>want to display another data field in the grid. I always add all the
>fields in the table (by double-clicking on the table object) and then
>I make visible only those fields I want to display. In that way, I can
>simple make a field visible to add a column displaying that field.
>        ... or I could be completely misinterpreting your question! :-)

Dan,

Thanks for your reply.  Yes, you misunderstood my question.  So let me try
again <G>.

I have a DBGrid connected to an open Query.  There are 3 columns in this
grid.  I want to add a 4th column.  It is a calculated column derived from
the original columns.  So I do a DBGrid.Columns.Add which results in the
clearing of the original 3 columns and replaced with one new empty column.  
Am I doing something wrong?

Lito

Lito Dizon
adi...@us.net

Re:Adding New DBGrid Column at Runtime???


Quote
adi...@mail.us.net wrote:
> I'm trying to add a new DBGrid column at runtime by calling the Add method
> like this:
> DBGrid.Columns.Add
> The result is all the original columns are removed from the grid, and a new
> column without a title is added.  Subsequent calls to the same Add method
> result in new columns.
> Question:  How do I add a new column without clearing the original columns?

How have you set up your columns in the Grid?  If you are relying on
them being in the Dataset, and haven't put them up using the DBGrid
Editor, then they aren't actually there, Delphi just puts them up if no
fields are specified.  You should doubleclick on the DBGrid to run the
Editor, add all of the columns you want in the default mode, and *then*
in your program the add method should work.

Oliver

Re:Adding New DBGrid Column at Runtime???


It sounds like you don't have any columns at all defined when you open your
query.
When you display a grid without defining columns, it just uses whatever
properties
it gets from the fields in the table(s) you are displaying.  So, when you
try and define
a new column on the grid, the grid must show ALL of it's columns by using
the
properties of each Column object.  So, you can either define the first 3
columns
at design time with the property editor, OR, you can define all 4 at the
same time
in code.

  In other words, I think that if you are going to define 1 column on a
grid with the
column object, you must define them all that way....Good luck!

--Shawn Clark
scl...@illuminet.net

Angelito Dizon <adi...@mail.us.net> wrote in article
<19111.adi...@mail.us.net>...

Quote
> On Sun, 08 Dec 1996 21:58:49 GMT,
> Dan Gilbert  <dgpc...@{*word*104}ia.com> wrote:

> >        Since you're using a DBGrid and not a string grid, I assume you
> >want to display another data field in the grid. I always add all the
> >fields in the table (by double-clicking on the table object) and then
> >I make visible only those fields I want to display. In that way, I can
> >simple make a field visible to add a column displaying that field.
> >        ... or I could be completely misinterpreting your question! :-)

> Dan,

> Thanks for your reply.  Yes, you misunderstood my question.  So let me
try
> again <G>.

> I have a DBGrid connected to an open Query.  There are 3 columns in this
> grid.  I want to add a 4th column.  It is a calculated column derived
from
> the original columns.  So I do a DBGrid.Columns.Add which results in the
> clearing of the original 3 columns and replaced with one new empty
column.  
> Am I doing something wrong?

> Lito

> Lito Dizon
> adi...@us.net

Re:Adding New DBGrid Column at Runtime???


On 10 Dec 1996 22:03:16 GMT,
Shawn Clark  <scl...@illuminet.net> wrote:

Quote
>It sounds like you don't have any columns at all defined when you open your
>query.

Thanks for your reply.

As I mentioned in my original post, there were 3 columns in the dbgrid.  
They disappeared when I did a dbgrid.columns.add.

Lito

Lito Dizon
adi...@us.net

Re:Adding New DBGrid Column at Runtime???


Hi All!
May be who have documentation on Oracle SQL*Net v2
I can read any format
Please send me by E:mail

Re:Adding New DBGrid Column at Runtime???


You could structure your query to include a NULL field in the recordset.
For example:
SELECT DISTINCTROW Categories.[Category ID], Categories.[Category Name],
Categories.Description, Null AS CalcdField
FROM Categories;

I don't know if this will work; just an idea.

Quote
Angelito Dizon wrote:

> On 10 Dec 1996 22:03:16 GMT,
> Shawn Clark  <scl...@illuminet.net> wrote:

> >It sounds like you don't have any columns at all defined when you open your
> >query.

> Thanks for your reply.

> As I mentioned in my original post, there were 3 columns in the dbgrid.
> They disappeared when I did a dbgrid.columns.add.

> Lito

> Lito Dizon
> adi...@us.net

Other Threads