BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

TDBGridColumns Problem

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Desktop)
View previous topic :: View next topic  
Author Message
Martyn Davies
Guest





PostPosted: Fri Apr 16, 2004 2:23 am    Post subject: TDBGridColumns Problem Reply with quote




Hi

Does anyone know of a way of finding out if a field is
currently being displayed in a TDBGrid without iterating
through the columns?

Is there some way TDBGridColumns as a collection can be
used for his purpose, perhaps - something like FindItemId,
maybe?

Using D5pro, XP, MSAccess97

Any help greatly appreciated.

Regards

Martyn Davies





Back to top
Bill Todd (TeamB)
Guest





PostPosted: Fri Apr 16, 2004 3:46 am    Post subject: Re: TDBGridColumns Problem Reply with quote



A quick check of the methods of TDBGridColumns in the on-line help
shows no such method. :)

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
Back to top
Martyn Davies
Guest





PostPosted: Fri Apr 16, 2004 4:45 am    Post subject: Re: TDBGridColumns Problem Reply with quote




Quote:
A quick check of the methods of TDBGridColumns in the on-line help
shows no such method. Smile

Hi Bill

Thanks for your response.

According to the help on TCollection, FindItemId is one
of its methods. If TDBGridColumns is descended from
TCollection, shouldn't I be able to reference TColumn items as
TCollection items and find out if the field I'm looking for
is in the collection?

Something along the lines of:

....
var
i: Integer;

TCollection(dgProduct.Columns).FindItemId(MyColumnIndex)
....

Trouble is, I know the FieldName but not its ColumnIndex.


Regards

Martyn Davies

Back to top
Mike Shkolnik
Guest





PostPosted: Fri Apr 16, 2004 8:33 am    Post subject: Re: TDBGridColumns Problem Reply with quote

The TDBGrid have the SelectedField property where you may get the current
selected field

--
With best regards, Mike Shkolnik
EMail: [email]mshkolnik (AT) scalabium (DOT) com[/email]
http://www.scalabium.com

"Martyn Davies" <martyncd (AT) ctrlx (DOT) hotmail.com> wrote

Quote:

Hi

Does anyone know of a way of finding out if a field is
currently being displayed in a TDBGrid without iterating
through the columns?

Is there some way TDBGridColumns as a collection can be
used for his purpose, perhaps - something like FindItemId,
maybe?

Using D5pro, XP, MSAccess97

Any help greatly appreciated.

Regards

Martyn Davies








Back to top
Martyn Davies
Guest





PostPosted: Fri Apr 16, 2004 1:21 pm    Post subject: Re: TDBGridColumns Problem Reply with quote


"Mike Shkolnik" <mshkolnik2002 (AT) ukr (DOT) net> wrote:
Quote:
The TDBGrid have the SelectedField property where you may get the current
selected field

Thanks for your input, Mike


However, let me clarify...

I have a grid which may show any number and any combination
of fields from a dataset of 43 fields. I need to find out if
any one of the 43 fields is currently being displayed in the
grid.

Regards

Martyn Davies

Back to top
Bill Todd (TeamB)
Guest





PostPosted: Fri Apr 16, 2004 1:29 pm    Post subject: Re: TDBGridColumns Problem Reply with quote

On 15 Apr 2004 21:45:08 -0700, "Martyn Davies"
<martyncd (AT) ctrlx (DOT) hotmail.com> wrote:

Quote:
Trouble is, I know the FieldName but not its ColumnIndex.

Exactly. That was obvious from your original message and there is no
way to search the collection by field name. You will have to write
your own method to loop through the columns collection to find the
name you want.

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)

Back to top
Quasidata
Guest





PostPosted: Sun Apr 18, 2004 6:01 am    Post subject: Re: TDBGridColumns Problem Reply with quote

Hello Martyn,

Here is a sample.

procedure TForm1.Button1Click(Sender: TObject);
const
MyFieldName = '';
var
MyColumn: TColumn;
begin
MyColumn := MyFindColumn(MyFieldName);
if Assigned(MyColumn) then
Caption := IntToStr(MyColumn.Index);
end;

function TForm1.MyFindColumn(const AFieldName: string): TColumn;
var
MyColumns: TDBGridColumns;
I: Integer;
begin
MyColumns := DBGrid1.Columns;
for I := 0 to MyColumns.Count - 1 do begin
Result := TColumn(MyColumns[I]);
if AnsiCompareText(Result.FieldName, AFieldName) = 0 then Exit;
end;
Result := nil;
end;

--
Andrei Fomine www.quasidata.com
DbAltGrid - multi-line layout, RTF and graphics of any kind in DBGrid.
Transfer@Once - full-blown clipboard and drag-and-drop data transfer to/from
any control in many formats, including ones native to MS Office.


"Martyn Davies" <martyncd (AT) ctrlx (DOT) hotmail.com> wrote

Quote:

Hi

Does anyone know of a way of finding out if a field is
currently being displayed in a TDBGrid without iterating
through the columns?

Is there some way TDBGridColumns as a collection can be
used for his purpose, perhaps - something like FindItemId,
maybe?

Using D5pro, XP, MSAccess97

Any help greatly appreciated.

Regards

Martyn Davies







Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Desktop) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.